CPEN 461/661, Spring 1997 |
OpenGL Tutorial |
Animation in computer graphics is achieved through the use of double buffering. Double buffering provides two complete color buffers for use in drawing. The frame in one buffer is displayed while the the frame in the other buffer is being drawn. When the drawing of a frame is complete the two buffers are swapped so that the one that was being viewed is now used for drawing.
OpenGL does not provide a command for buffer swapping since it is up to the windowing system to provide and control the buffers. The tk library provides the command tkInitDisplayMode(TK_DOUBLE | any other modes . . .) to specify use of two color buffers for double buffering. The tk command tkSwapBuffers() must be called to swap between the two buffers. This command is generally called at the end of the drawing procedure after a call to glFlush().
Animation is achieved in the event loop by assigning the drawing procedure to be the procedure called when no events are received. This is done using the command tkIdleFunc().