A Display List is a cache of OpenGL commands that can be executed with a single call. OpenGL holds all the transforms or whatever in memory until they are called, and does not recalculate everything every frame. Some GL commands cannot be used inside the list definition, this is from MSDN...
So, if your draw code is something like this pseudocode..Quote:
Certain commands are not compiled into the display list, but are executed immediately, regardless of the display list mode. These commands are glColorPointer, glDeleteLists, glDisableClientState, glEdgeFlagPointer, glEnableClientState, glFeedbackBuffer, glFinish, glFlush, glGenLists, glIndexPointer, glInterleavedArrays, glIsEnabled, glIsList, glNormalPointer, glPopClientAttrib, glPixelStore, glPushClientAttrib, glReadPixels, glRenderMode, glSelectBuffer, glTexCoordPointer, glVertexPointer, and all of the glGet routines.
Similarly, glTexImage2D and glTexImage1D are executed immediately and not compiled into the display list when their first argument is GL_PROXY_TEXTURE_2D or GL_PROXY_TEXTURE_1D, respectively.
When the glEndList function is encountered, the display list definition is completed by associating the list with the unique name list (specified in the glNewList command). If a display list with name list already exists, it is replaced only when glEndList is called.
The glCallList and glCallLists functions can be entered into display lists. The commands in the display list or lists executed by glCallList or glCallLists are not included in the display list being created, even if the list creation mode is GL_COMPILE_AND_EXECUTE.
You can optimize that using a display list and putting the glBegin/glEnd set into the list (along with any other OpenGL calls that are the same for every object).Code:for (every object to be drawn) {
glLoadIdentity();
glTranslatef(object location);
glBegin(POLY_TYPE);
//draw geometry
glEnd();
}
Setup the list during your program initinilization, and then in your draw code you just call glCallList(object id). Which is essentally, a function call to everything you put in the list, only faster because its already been calculated and saved behind the scenes by OpenGL. I use display lists alot, if you have a thousand different objects, then your probably dont want to create a display list for each. But if you have a few dozen, then display lists may be the way to go.Code:for (every object to be drawn) {
glLoadIdentity();
glTranslatef(object location);
glCallList(object id); //provided every object has the same geometry
}
The Red Book has an excellent chapter detailing the function and use of Display Lists.