// 0. Compile and run the code. Left click in the window, and choose the menu options. // Are they functional? // 1. Complete the code so that the menus three options are functional: // (a) quit // (b) double the size of the box // (c) halve the size of the box // 2. Finally, modify the code so that a main menu provides the option of choosing // from two subMenus: // (a) a color menu, which changes the color of the box // (b) a size menu which functions as above #include #include #define WINDOWSIZE 400 GLint size = 100; void myInit() { glClearColor(1.0,1.0,1.0,0.0); glColor3f(0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0,WINDOWSIZE,0.0,WINDOWSIZE); glMatrixMode(GL_MODELVIEW); } void display() { glClear(GL_COLOR_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); glBegin(GL_POLYGON); glVertex2f(0.0,0.0); glVertex2f(size,0.0); glVertex2f(size,size); glVertex2f(0.0,size); glEnd(); glFlush(); } void menu (GLint id) { switch (id) { case 1: break; case 2: break; case 3: break; } glutPostRedisplay(); } void mainMenu (GLint id) { switch (id) { case 1: exit(0); break; } glutPostRedisplay(); } int main (int argc , char **argv) { GLint subMenu1, subMenu2; glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(WINDOWSIZE,WINDOWSIZE); glutInitWindowPosition(0.0,0.0); glutCreateWindow("MenuDemo"); myInit(); glutDisplayFunc(display); glutCreateMenu(menu); glutAddMenuEntry("quit",1); glutAddMenuEntry("bigger square",2); glutAddMenuEntry("smaller square",3); glutAttachMenu(GLUT_LEFT_BUTTON); glutMainLoop(); return 0; }