280 Introduction to C++ Programming and Graphics
//--- main:
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUTDEPTH | GLUTSINGLE | GLUTRGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
win=glutCreateWindow("Goulis");
glClearColor(0.2,0.5,0.2,0.2);
glutDisplayFunc(showme); // initial display
showmenu();
glutDisplayFunc(showme);
glutMainLoop();
return 0;
}
//--- showme:
void showme(void)
{
glClear(GLCOLORBUFFERBIT);
if(drawflag==1){
glutPostRedisplay();}
else if(drawflag==2){
glutWireTeapot(0.5);}
else if(drawflag==3){
glBegin(GLTRIANGLES);
glVertex3f(-0.9,-0.5,0.0);
glVertex3f( 0.3,-1.0,0.0);
glVertex3f( 0.0, 1.0,0.0);
glEnd();}
glFlush();
}
//--- showmenu:
void showmenu(void)
{
submenuid=glutCreateMenu(menu); // Create a sub-menu
glutAddMenuEntry("teapot", 2); // Add sub menu entries
glutAddMenuEntry("triangle", 3); // Create an entry
menuid=glutCreateMenu(menu); // Create the menu
glutAddMenuEntry("Clear", 1); // Create an entry
glutAddSubMenu("Draw", submenuid); // Create an entry