OpenGL Labs

CS 320

Feb 16, 2011

Color Cube

Open a new OpenGL project. Go to the course web site, download cube.c, import it into your project, and do the following:

  1. Compile and run the program. Use the x, y, and z keys to change the axis of rotation. The escape key will terminate the program. Note the smoothness of the color transitions on the cube. Do the rotation axes appear to be fixed or do they shift about?

  2. Near the top of the source code, comment-out the preprocessor definition of DEPTH. Compile and run. Describe what happens. What is going on? Restore the definition when you are finished.

  3. (Don't try this on an empty stomach.) Change the value of zNear in the two glOrtho() calls in myReshape() to 0.0. Predict the result. Was your prediction correct?

ViewPorts

Open a new OpenGL project. Go to the course web site, download viewport.c, import it into your project, and do the following (don't run the program until you're told to do so):

  1. Study the source code to determine how the mouse controls the two state variables
    maintainAspectRatio and realtimeRedraw.

  2. The list display list created in main() stores the vertices of the two polygons in a list so that the list call be called later (in display()) to speed rendering. Note that the display list completely covers the clipping region.

  3. Look at display() and note how the calls to glViewport() are being used to change the mapping from world coordinates to window coordinates. Execute the code ``by hand'' to predict what will be displayed when you run the program.

  4. Run the program. Was your display prediction correct? Experiment with resizing the window: Try both aspect ratio modes and observe the differences. What does realtimeRedraw do, exactly? Explain what's going on with it. Tap the escape key to exit.

  5. Under what conditions is reshape() called?

  6. Assuming that maintainAspectRatio is true, explain how reshape() works.

  7. Look at idle() to see how text is displayed. Suggest a better way.



Thomas P. Kelliher 2011-02-15
Tom Kelliher