hide random home http://www.sgi.com/tech/openGL/mjk.xlib/subsubsection3_2_5_1.html (Silicon Surf Promotional CD, 01/1995)



Next: 2.5.2 Window Resizing Up: 2.5 Event Dispatching Previous: 2.5 Event Dispatching

2.5.1 Expose Handling

For an Expose event, the example program just sets a flag indicating the window needs to be redrawn. The reason is that Expose events indicate a single sub-rectangle in the window that must be redrawn. The X server will send a number of Expose events if a complex region of the window has been exposed.

For a normal X program using 2D rendering, you might be able to minimize the amount needed to redraw the window by carefully examining the rectangles for each Expose event. For 3D programs, this is usually too difficult to be worthwhile since it is hard to determine what would need to be done to redraw some sub-region of the window. In practice the window is usually redrawn in its entirety. For the dinosaur example, redrawing involves calling the dinosaur display list with the right view. It is not helpful to know only a sub-region of the window actually needs to be redrawn. For this reason, an OpenGL program should not begin redrawing until it has received all the expose events most recently sent to the window. This practice is known as expose compression and helps to avoid redrawing more than you should.

Notice that all that is done to immediately handle an expose is to set the needRedraw flag. Then XPending is used to determine if there are more events pending. Not until the stream of events pauses is the redraw routine really called (and the needRedraw flag reset).

The redraw routine does three things: it clears the image and depth buffers, executes the dinosaur display list, and either calls glXSwapBuffers on the window if double buffered or calls glFlush. The current model-view matrix determines in what orientation the dinosaur is drawn.


mjk@asd.sgi.com
Wed Oct 19 18:11:46 PDT 1994