OpenGL Lab: Menus, Selection,
Display Lists, and ``Animation''

CS 320

Mar. 9, 2009

  1. Create a new OpenGL project, grab poly.c from the class home page, and add it to the project.

  2. Compile and run the program, experimenting with it a bit.

  3. Add a menu tool to allow drawing triangles.

  4. Add a drawing mode to the menu to allow drawing either a filled or unfilled object.

  5. Add a set of display lists for ASCII text, as discussed in class and add an elapsed time clock in the upper right hand corner of the canvas. The elapsed time should update once per second.

    Hints:

    1. The time() function returns the number of seconds since the beginning of the ``Epoch:''
         #include <time.h>
         #include <stdlib.h>
      
         int startTime = time(NULL);
      

    2. Using a start time and a current time, you can easily compute the number of elapsed seconds. Using modulo arithmetic, you can convert elapsed seconds to elapsed hours, minutes, and seconds for your display.

    3. The sprintf() function can be used to create the time string:
         #include <stdio.h>
      
         char timeString[80];
      
         sprintf(timeString, "%2d:%02d:%02d", elapsedHours, elapsedMinutes,
                 elapsedSeconds);
      

    4. You can either register an idle callback and spin on the time() call (Why is this inefficient?), or register a timer callback (see documentation for gluttimerfunc). If you use gluttimerfunc (and you should), why should you sample the time more than once per second? What's a reasonable sampling period?

  6. Explain why the elapsed time string has so much ``jitter.''

  7. Add a menu choice to allow resetting the elapsed time to 0.



Thomas P. Kelliher 2009-03-09
Tom Kelliher