Background for Assignment 3

You can assign a mouse button to bring up a menu of options, which can include submenus. Here's an example without submenus:
#include <GL/glut.h>

void myinit(void)
{
 
/* attributes */

        glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
        glColor3f(0.0, 0.0, 0.0); /* draw in black */

/* set up viewing */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0.0, 500.0, 0.0, 500.0);
        glMatrixMode(GL_MODELVIEW);
}

void display( void )
{
        glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */
        glFlush(); /* clear buffers */
 }

void mymenu(int x)
{
        switch(x){
        case 0:
        glClearColor(1.0, 0, 0, 1.0); /* red background */
                break;  
        case 1:
        glClearColor(0,1.0, 0, 1.0); /* green background */
                break;
        case 2:
        glClearColor(0,0,1.0, 1.0); /* blue background */
                break;
        }
        glutPostRedisplay();
}

void main(int argc, char** argv)
{

/* Standard GLUT initialization */

        glutInit(&argc,argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
        glutInitWindowSize(500,500); /* 500 x 500 pixel window */
        glutInitWindowPosition(0,0); /* place window top left on display */
        glutCreateWindow("Test"); /* window title */
        glutDisplayFunc(display); /* display callback invoked when window opened */
        
        glutCreateMenu(mymenu);
        glutAddMenuEntry("Red",0);
        glutAddMenuEntry("Green",1);
        glutAddMenuEntry("Blue",2);
        glutAttachMenu(GLUT_RIGHT_BUTTON);
        myinit(); /* set attributes */
        
        glutMainLoop(); /* enter event loop */
}
Here's an example which includes a submenu:
#include <GL/glut.h>

void myinit(void)
{
 
/* attributes */

        glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
        glColor3f(0.0, 0.0, 0.0); /* draw in black */

/* set up viewing */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluOrtho2D(0.0, 500.0, 0.0, 500.0);
        glMatrixMode(GL_MODELVIEW);
}

void display( void )
{
        glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */
        glColor3b(128,0,0);
        glBegin(GL_LINES);
                glVertex2f(0,0);
                glVertex2f(500,500);
        glEnd(); 
    glFlush(); /* clear buffers */
 }

void mymenu(int x)
{
}
void colorselect(int x)
{
        switch(x){
        case 0:
        glClearColor(1.0, 0, 0, 1.0); /* red background */
                break;  
        case 1:
        glClearColor(0,1.0, 0, 1.0); /* green background */
                break;
        case 2:
        glClearColor(0,0,1.0, 1.0); /* blue background */
                break;
        }
        glutPostRedisplay();
}

void main(int argc, char** argv)
{

/* Standard GLUT initialization */

        glutInit(&argc,argv);
        glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
        glutInitWindowSize(500,500); /* 500 x 500 pixel window */
        glutInitWindowPosition(0,0); /* place window top left on display */
        glutCreateWindow("Test"); /* window title */
        glutDisplayFunc(display); /* display callback invoked when window opened */
        
        int cs=glutCreateMenu(colorselect);
        glutAddMenuEntry("Red",0);
        glutAddMenuEntry("Green",1);
        glutAddMenuEntry("Blue",2);
        glutCreateMenu(mymenu);
        glutAddMenuEntry("one",0);
        glutAddSubMenu("Select color",cs);
        glutAttachMenu(GLUT_RIGHT_BUTTON);
        myinit(); /* set attributes */
        
        glutMainLoop(); /* enter event loop */
}