1. In a GLUT program, how is control passed back to the programmer? How is this set up during initialization?

Control is passed back to the programmer through callback functions. In this example, we set up event handlers in main by calling glutDisplayFunc, glutReshapeFunc, and glutKeyboardFunc with the corresponding function pointers. So when a a display, reshape, or keyboard event happens, for example, the functions we specified as the arguments to glutDisplayFunc, glutReshapeFunc, and glutKeyboardFunc are signaled and executed. Thus, the programmer can get control back by specifying which events to wait on.

2. What does the parameter to glutInitDisplayMode() in main() specify?

The parameter to glutInitDisplayMode() in main() specifies the initial display mode. The function receives an unsigned int. The argument is normally the bitwise OR-ing of GLUT display mode bit masks. In this example, the initial display mode is GLUT_RGBA | GLUT_DOUBLE, meaning that it is a double buffered RGBA display mode. There are other options that specify buffering and colors as well; in order to add more options you would have to OR them together.

3. What do the calls to glOrtho() and glViewport() in the reshape() function accomplish? If the window is to be resized, why might we want to change this?

glOrtho() establishes the coordinate system the window will be using and how the final image will be mapped; the arguments to the function specify the mapping between the window and the clipping planes. However, in this example we are only using a 2D surface it only specifies the coordinate system.

glViewport()specifies the drawing region; it specifies the lower left corner and the width and height of the region. Specifically, it specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd, ynd) be normalized device coordinates.

If the window is resized, the coordinate system is altered along with the window size. Thus, objects already drawn on the canvas will become skewed and/or stretched. If we want to maintain the aspect ratio or absolute size of the objects we already drew, we will need to change the coordinate system when the window size changes through glOrtho().


My program prompts the user to: "Please enter a number between 0 and 2; 0 for Rock, 1 for Paper, 2 for Scissors -- Any number not within range will default to rock: "

It draws a red circle for a rock, a green square for paper, and a blue cross for scissors upon the user input.