Display Lists<< Primitives And Attributes | Table of Contents | >>
Every time a window has to be redisplayed, the commands needed to generate the image has to be sent to the graphics server. For large numbers of instructions, this can be time-consuming. To help improve performance, especially in action based applications, OpenGL provides the display lists. A display list, which contains a sequence of graphics operations or commands, can be constructed by the client and saved on the graphics server. When the contents of the display list is needed, the instructions do not have to be retransmitted to the server but instead a single instruction is transmitted indicating a specific display list should be used. The performance of the graphics system can be greatly improved when display lists are used in large client applications. But they do come at a cost. Since the display lists are stored on the graphics server, they consume memory on the server. In addition, building and modifying display lists can be time-consuming. Thus, they should be limited to a collection of commands and/or data that seldom change. Defining the ListA display list is created and defined in a similar fashion to the geometric primitives. The graphics commands to be contained in the list are specified between a pair of {f:glNewList} and {f:glEndList} functions. (:source lang=cpp:)/* Positive integers are used to name display lists. */ const int TRIANGLE_LIST = 1 /* Define a new display list containing a triangle. */ glNewList( TRIANGLE_LIST, GL_COMPILE ); glBegin( GL_POLYGON ); glColor3f( 1.0, 0.0, 0.0 ); glVertex2f( 0.0, 1.0 ); glVertex2f( -1.0, -1.0 ); glVertex2f( 1.0, -1.0 ); glEnd(); glEndList(); The first argument to {f:glNewList} is a unique positive integer which is later used to identify the display list. After the list is constructed, it is sent to the server and saved but its contents are not executed. A display list can be redefined by simply specifying the index of a previously created lists. To delete a display list, use the {f:glDeleteLists} function. Executing the ListA previously created display list can be used within a sequence of graphics commands as if the contents of the list were explicitly stated. You can think of a display list as if it were a function containing a set of instructions that are executed when the function is called. To execute the instructions of a display list, the {f:glCallList} function is used along with the unique integer identification number assigned to our list of choice. (:source lang=cpp:)/* Display a triangle at the lower-left corner. */ glViewport( 0, 0, 100, 100 ); glCallList( TRIANGLE_LIST ); /* Display a second triangle in the upper-right corner. */ glViewport( 400, 400, 100, 100 ); glCallList( TRIANGLE_LIST ); Note that some OpenGL commands can not be used within a display lists. For a complete list of such commands, see the manual page for {f:glCallList}. Related Commands
|