扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
#include <GL/glut.h> #include <stdio.h> int menu,subMenu1,subMenu2; /*在蓝色的背景上绘制一个白色的正方形*/ void myDraw(void) { glClearColor(0.0,0.0,1.0,0.0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glColor3f(1.0,1.0,1.0); glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0); glBegin(GL_POLYGON); glVertex2f(-0.5,-0.5); glVertex2f(-0.5,0.5); glVertex2f(0.5,0.5); glVertex2f(0.5,-0.5); glEnd(); glutSwapBuffers(); } /*写出当前是哪个菜单*/ void GetCurrentMenu(void) { int nMenu; nMenu = glutGetMenu(); if(nMenu == menu) printf("The current menu is Main Menu.\n"); if(nMenu == subMenu1) printf("The current menu is SubMenu1.\n"); if(nMenu == subMenu2) printf("The current menu is SubMenu2.\n"); } /*子菜单1*/ void SubMenuFunc1(int data) { GetCurrentMenu(); switch(data) { case 1: printf("SubMenu1's item 1 is triggered.\n"); break; case 2: printf("SubMenu1's item 2 is triggered.\n"); break; case 3: printf("SubMenu1's item 3 is triggered.\n"); break; } } /*子菜单2*/ void SubMenuFunc2(int data) { GetCurrentMenu(); switch(data) { case 1: printf("SubMenu2's item 1 is triggered.\n"); break; case 2: printf("SubMenu2's item 2 is triggered.\n"); break; case 3: printf("SubMenu2's item 3 is triggered.\n"); break; } } /*主菜单*/ void MenuFunc(int data) { GetCurrentMenu(); switch(data) { case 1: printf("MainMenu's item 1 is triggered.\n"); break; case 2: printf("MainMenu's item 2 is triggered.\n"); break; case 3: printf("MainMenu's item 3 is triggered.\n"); break; } } int main(int argc,char ** argv) { /*初始化*/ glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(500,400); glutInitWindowPosition(100,100); /*创建窗口*/ glutCreateWindow(" MENU"); glutDisplayFunc(myDraw); /*创建子菜单1并加入菜单条目*/ subMenu1 = glutCreateMenu(SubMenuFunc1); glutAddMenuEntry("SubMenu1's item1",1); glutAddMenuEntry("SubMenu1's item2",2); glutAddMenuEntry("SubMenu1's item3",3); glutAttachMenu(GLUT_RIGHT_BUTTON); /*创建子菜单2并加入菜单条目*/ subMenu2 = glutCreateMenu(SubMenuFunc2); glutAddMenuEntry("SubMenu2's item1",1); glutAddMenuEntry("SubMenu2's item2",2); glutAddMenuEntry("SubMenu2's item3",3); glutAttachMenu(GLUT_RIGHT_BUTTON); /*创建主菜单并加入菜单条目及子菜单*/ menu = glutCreateMenu(MenuFunc); glutAddMenuEntry("Item1",1); glutAddMenuEntry("Item2",2); glutAddMenuEntry("Item3",3); glutAddSubMenu("SubMenu 1",subMenu1); glutAddSubMenu("SubMenu 2",subMenu2); glutAttachMenu(GLUT_RIGHT_BUTTON); glutMainLoop();//进入GLUT事件处理循环 return 0; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者