Example Program: box.cc

The cbKeyboard() function also accepts information from the system when it is invoked, in this case the key that was pressed and the location of the pointer (mouse). Since the glutMainLoop() never terminates, it is common to use a callback function to exit the program; this is done if a q, Q, or ESC key is pressed.

    if ( key == 'q' || key == 'Q' || key == 27 )
    {
        glutDestroyWindow( glutGetWindow() );
        exit( 0 );
    }