- Forward


Display Lists in OpenGL
An Introduction


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Motivation
Back SMYC Forward
  • So Far:
    • We have executed all OpenGL "commands" in immediate mode
  • A Drawback:
    • Many of the same operations are performed multiple times for no reason
  • A Solution:
    • Cache "commands" in a display list
Uses of Display Lists
Back SMYC Forward
  • Geometry:
    • For static presentations we might want to use the same "shape" multiple times (e.g., the wheels on a car)
    • For animations we might want to cache the entire "shape" and just transform it for each frame
  • Matrix Operations:
    • Both computed matrices and inverses can be stored in display lists
  • Remote Execution:
    • When using a remote server, display lists (which are part of the server state) are stored on the server and hence need not be re-transmitted
Steps in the Initialization Process
Back SMYC Forward
  • Name the display list
  • Create the display list
Steps in the Rendering Process
Back SMYC Forward
  • Transform, set material properties, etc.. as needed
  • Execute the display list
Naming Display Lists
Back SMYC Forward
  • The Function:
    • GLuint glGenLists(GLsizei range)
  • Argument:
    • The number of (contiguous) display lists to "name"
  • Return:
    • The index of the first display list (or 0 if there are too few unallocated display lists available)
Naming Display Lists (cont.)
Back SMYC Forward

An Example

openglexamples/displaylists/teapots.c (Fragment: name)
 
Creating Display Lists
Back SMYC Forward
  • The Functions:
    • void glNewList(GLuint name, GLenum mode) specifies the start of list with index name
    • void glEndList() specifies the end
  • Modes:
    • GL_COMPILE or GL_COMPILE_AND_EXECUTE
Creating Display Lists (cont.)
Back SMYC Forward

An Example

openglexamples/displaylists/teapots.c (Fragment: create)
 
Not Allowed in Display Lists
Back SMYC Forward
  • Commands that retrieve state information
  • Commands that set client state
Executing a Display List
Back SMYC Forward
  • The Functions:
    • void glCallList(GLuint name)
  • Scope:
    • Can be called from anywhere, as long as the OpenGL context that can access the display list is active
Executing a Display List (cont.)
Back SMYC Forward

An Example

openglexamples/displaylists/teapots.c (Fragment: use)
 
Hierarchical Display Lists
Back SMYC Forward
  • An Observation:
    • glCallList() can be called between calls to glNewList() and glEndList()
  • Implication:
    • Display lists can contain other display lists [normally up to a depth of 64; see void glGetIntegerv(GL_MAX_LIST_NESTING, GLint *depth ]
  • Common Uses:
    • Shapes that are composed of other shapes (e.g., a display list for a hand that contains five executions of a display list for a finger)
Executing Multiple Display Lists
Back SMYC Forward
  • Specifying the Offset in "Names":
    • void glListBase(GLuint offset)
  • Executing:
    • void glCallLists(GLsizei n, GLenum type, conts GLvoid* lists)
    • where type is usually GL_INT and lists is usually a pointer to an array of GLint "names"
There's Always More to Learn
Back -