Display Lists

<< Primitives And Attributes | Table of Contents | >>
(:toc:) The OpenGL graphics systems is based on a client-server model. The application is a client which issues commands that are interpreted and executed by the graphics server. The result is a digital image displayed on an output device. On a UNIX system, the graphics server is typically the X-Windows application which manages the desktop windowing environment and the output device is a desktop window.

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 List

A 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 List

A 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

glDeleteLists( list, count )
Deletes one or more display lists from the server releasing the memory used by the lists and freeing the integer identification numbers for reuse. {v:list} is the index of the first list to be deleted. {v:count} the number of contiguous lists to be deleted.
glCallLists( num, listType, indexList )
Executes multiple display lists identified by the indices contained in the {v:indexList} array. {v:num} indicates the number of indices contained in {v:indexList} and {v:listType} is the integer storage type of the array.
glGenLists( count )
Creates {v:count} contiguous empty display lists on the server. The unique index of the first display list is returned. This command can be used to let the server provide indices for the display lists.


<< Primitives And Attributes | Table of Contents | >>

Print - Changes - Search
Last modified: January 17, 2008, at 10:36 PM.