For example, suppose you want to apply a transformation to some geometric objects and then draw the result. Your code may look like this:
glNewList(1, GL_COMPILE); draw_some_geometric_objects(); glEndList(); glLoadMatrix(M); glCallList(1);
void glNewList (GLuint list, GLenum mode);Specifies the start of a display list. OpenGL routines that are called subsequently (until glEndList() is called to end the display list) are stored in a display list, except for a few restricted OpenGL routines that can't be stored. (Those restricted routines are executed immediately, during the creation of the display list.) list is a nonzero positive integer that uniquely identifies the display list. The possible values for mode are GL_COMPILE and GL_COMPILE_AND_EXECUTE. Use GL_COMPILE if you don't want the OpenGL commands executed as they're placed in the display list; to cause the commands to be executed immediately as well as placed in the display list for later use, specify GL_COMPILE_AND_EXECUTE.
void glEndList (void);Marks the end of a display list.
void glCallList (GLuint list);This routine executes the display list specified by list. The commands in the display list are executed in the order they were saved, just as if they were issued without using a display list. If list hasn't been defined, nothing happens.
Each display list is identified by an integer index. When creating a display list, you want to be careful that you don't accidentally choose an index that's already in use, thereby overwriting an existing display list.
Use glGenLists() to obtain unused display-list indices or use glIsList() to determine whether a specific index is in use.
In the following example, a single index is requested, and if it proves to be available, it's used to create a new display list:
listIndex = glGenLists(1);
if (listIndex != 0) {
glNewList(listIndex,GL_COMPILE);
...
glEndList();
}
Note: Zero is not a valid display-list index.
You can explicitly delete a specific display list or a contiguous range of lists with glDeleteLists(). Using glDeleteLists() makes those indices available again.