OpenGL Labs

CS 320

Feb 2, 5, 2001

2-D Drawing in OpenGL

Open a new OpenGL project in Visual C. Go to the course web site, download twodim.cpp and do the following:

  1. Make the one modification at the beginning of main() necessary for reading a scaling factor from the command line.

  2. Complete the following stub functions: paint(), line(), boxOutline(), and boxFill().

  3. Comment-out the call to paint() in redisplay(), calling it at the end of main(), just before the glutMainLoop() call. Predict what will happen as a result of this change. Was your prediction correct? Restore the original call sequence when you're finished.

  4. Comment-out the call to glFlush() in redisplay(). Predict what will happen. Was your prediction correct?

Color Cube

Open a new OpenGL project in Visual C. Go to the course web site, download cube.c and do the following:

  1. Make sure your display settings are set to TrueColor. 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. Set the display setting to 256 colors and re-run the program. Describe the changes in the cube's color transitions. What is going on? Set the frame buffer depth to a reasonable value when you're finished. (Because of the limited amount of RAM on these video cards, 64K colors is probably the best choice.)

  3. 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.

  4. (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 in Visual C. Go to the course web site, download viewport.c 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 complete covers the clipping region.

  3. Look at display() and note how the calls to glViewport() are being used the 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
Mon Feb 5 08:09:00 EST 2001
Tom Kelliher