- At the top of the program (before the function code), define a constant integer to represent the menu choice to quit the program and declare that the default drawing mode is a filled polygon.
/*
** menu management
*/
#define QUIT -999
GLenum mode = GL_POLYGON;
- Add the following function above setUpGLUT.
void setUpMenus(){
int mMenu;
mMenu=setUpModeMenu();
glutCreateMenu(mainMenu);
glutAddSubMenu("specify primitive mode",mMenu);
glutAddMenuEntry("quit",QUIT);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}
- Call this function from setUpGLUT, just before registering callbacks. If you put the call in the wrong position, you may run into trouble.
- Write the code for setting up the mode menu (above setUpGLUT).
int setUpModeMenu(){
int id;
id=glutCreateMenu(modeMenu);
glutAddMenuEntry("vertices",GL_POINTS);
glutAddMenuEntry("line loop",GL_LINE_LOOP);
glutAddMenuEntry("filled polygon",GL_POLYGON);
glutAddMenuEntry("lines",GL_LINES);
return id;
}
- Write the code for the main menu and the mode menu (above setUpModeMenu). Note the call to glutPostRedisplay. This causes GLUT to call your display function again. Never call display directly.
void mainMenu(int choice){
if(choice==QUIT)
exit(0);
}
void modeMenu(int choice){
mode=choice;
glutPostRedisplay();
}
- Replace the renderView function with the following code. This renders the square in red using the mode chosen from the menu (filled polygon by default).
void renderView(){
glColor3fv(colour[red]);
render(square,numVertices,mode);
}