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().
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.