void spinCube(void)
{

/* Idle callback, spin cube 2 degrees about selected axis */

        theta[axis] += inc;
        if( theta[axis] > 360.0 ) theta[axis] -= 360.0;
        display();
}

void keyboard(unsigned char key, int x, int y)
{

/* keyboard callback, selects an axis about which to rotate */

        if(key=='x'||key=='X') axis = 0;
        if(key==' '){
                axis=0;
                for(int i=0;i<3;i++)theta[i]=0;
                inc=2;
        }
        else if(key=='+')inc+=.1;
        else if(key=='-')inc-=.1;
        else if(key=='y'||key=='Y') axis = 1;
        else if(key=='z'||key=='Z') axis = 2;
        else if(key=='q'||key=='Q') exit(0);
}

..
void main(int argc, char **argv)
{
    glutInit(&argc, argv);

/* need both double buffering and z buffer */

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutCreateWindow("colorcube");
    glutReshapeFunc(myReshape);
    glutDisplayFunc(display);
    glutIdleFunc(spinCube);
    glutKeyboardFunc(keyboard);
    glEnable(GL_DEPTH_TEST); /* Enable hidden--surface--removal */
    glutMainLoop();
}