Please send me your comments
Display Lists Tutorial


Without Display Lists
Creating a DL
The Greedy Approach
Using Nested Display Lists
Other Considerations

Visual C++ project

[Previous: The Greedy Approach] [Next: Other Considerations]

Using Nested Display Lists

OpenGL provides one more possibility when using Display Lists: we can define a Display List inside another Display List.

This approach allows us to build a Display List for the snowman, and call this Display List inside the Display List for the loop. The code to create the Display Lists is as follows:

GLuint createDL() {
	GLuint snowManDL,loopDL;

	snowManDL = glGenLists(1);
	loopDL = glGenLists(1);


	for(int i = -3; i < 3; i++)
		for(int j=-3; j < 3; j++) {
			glTranslatef(i*10.0,0,j * 10.0);


The code to render the scene remains the same as in the previous version. In terms of frames per second there isn't a significant difference between this version and the one where only the individual snowman was placed in a display list. There seems to be an increase of one frame per second, i.e. 154fps, but as this timing method isn't exact the difference is not significative. The only difference in terms of the display list is that the translations that are placed inside the loops are now part of the display list.

The full source code is available here. The Visual C++ project.

In the application you can use the keys 'a' and 's' to rotate the camera, and 't' and 'g' to move forward and backwards respectively.

Using nested display lists a hierarchical model of an object can be built. Note that there is a limit to the nesting level of display lists. according to the official spec this value should be at least 64. To check what is the nesting value for your particular implementation of OpenGL you can use the function glGetIntegerv:

glGetIntegerv(GL_MAX_LIST_NESTING,GLint *maxlevel)

The value of maxlevel is the supported nesting level.

[Previous: The Greedy Approach] [Next: Other Considerations]