Ryan Williams ryanw1

Before my responses to the questions, some notes on my program:

I chose to construct the timeless classic "Technicolor cube with two triangles hovering around it" for my program. The construction is initially spinning; the direction of this spin can be adjusted using the four arrow keys. In addition, the r, g, and b keys toggle the red, green, and blue (respectively) components of the triangles' color (initially (1, 1, 0) = yellow) and the i and o keys adjust zooming speed in and out of the scene. I hope this is something along the lines of what was required! I didn't quite have time to learn enough to figure out why the faces of the cube sometimes appear in front of others that they shouldn't and other weird depth-perception problems, but I'm sure it's just some dumb thing I'm missing.

Anyway, here are my answers to the questions:

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 using special functions that the programmer chooses: the DisplayFunc, ReshapeFunc, KeyboardFunc, etc., that are fired when significant events occur during the execution of the program, allowing the programmer to handle a wide range of events appropriately. This structure is all set up initially in the main() function, where the programmer, in addition to initializing the window, sets a custom-made function for each event he wants to handle, that then gets fired at the appropriate times during execution. The entire event-processing loop is set into motion by the final call to glutMainLoop();

2) What does the parameter to glutInitDisplayMode() specify?

The parameters to glutInitDisplayMode() give the programmer a chance to toggle various options about the way his code will be run. In my submission, activating the GLUT_RGBA bit specifies that the window be created in RGBA mode (the alternative being color index mode, as far as I can tell?) while the GLUT_DOUBLE bit instructs the program to use a double buffer for smoother rendering, which helps the smoothness of animations by rendering frames fully on a behind-the-scenes buffer and then swapping buffers when the rendering is complete.

3) What do the calls to glOrtho() and glViewport() accomplish?

glOrtho() gives a matrix that scales the viewpoint of the camera, in this case making sure things stay oriented correctly in the event of a resize. I also use it in the idleFunc (with a tiny increment or decrement) to zoom in and out. The glViewport() call specifies the coordinates that should correspond to the field of view of the window, also necessary to make sure things appear properly scaled in the event of a resize.