Display Lists

Display lists are lists of OpenGL commands to be called all at once. Display lists are useful because OpenGL has to process all the drawing commands only once. From then on, calling a display list causes OpenGL to quickly perform all the operations within the display list without having to go through the overhead of a function call for each operation. Display lists are also very useful if you have hardware texture memory and are using more than one texture, as this is the only way to guarantee the system that your texture memory has not changed and therefore the hardware texture memory can be used.

In order to create a display list, you must first get a display list identifier. This is simply an unsigned integer. Any time you refer to a display list, you will refer to it by this number. The function call glGenLists(1) will return an unused display list identifier. Use this call to guarantee that you will not be clobbering over some other display list that you previously allocated. A call to glGenLists() with a number greater than 1 will generate that many contiguous display list identifiers, returning the lowest numbered identifier.

Once you have a display list identifier, you must put "stuff" into the display list. This is done with the glNewList() command. The following code chunk puts a triangle into a display list:

	GLuint displayList;
	displayList = glGenLists(1);
	glNewList(displayList,GL_COMPILE);
	glBegin(GL_TRIANGLES);
	glColor3f(1,0,0);
	glVertex3f(1,0,0);
	glVertex3f(0,1,0);
	glVertex3f(0,0,1);
	glEnd();
	glEndList();
The glNewList() call must specify the display list identifier the following set of commands corresponds to. Note that if you specify a display list identifier that already has commands associated with it, these will be wiped out and replaced by the new commands. The glEndList() call marks the end of the display list specification.

Once you have created a display list you can execute the commands within it with the glCallList() call. You call this function with the display list identifier you used when creating your display list and it will call all the commands within the display list.

	glCallList(displayList);
will execute the display list we created above.

Display lists can be hierarchical. In other words, you can have a glCallList() command within glNewList() and glEndList().

Using Texture Maps with Display Lists

In order to place a texture map definition within a display list, simply place the glTexture2D() inside a display list definition:
	GLuint textureDisplayList;
	textureDisplayList = glGenLists(1);
	glNewList(textureDisplayList,GL_COMPILE);
	glTexture2D(...);
	glEndList();
From now on, whenever you call glCallList(textureDisplayList), that texture will become the current texture.