io7m | single-page | multi-page | archive (zip, signature)
2. Immediate modeA Brief History Of Vertex Specification In OpenGL 4. Vertex Arrays
PreviousUpNext

Display Lists
Display lists were a means of compiling a list of OpenGL instructions and executing them at a later date. They were arguably not a means of vertex specification, specifically (pun intended) but were often used to improve the speed of doing so. They are covered here for the sake of completeness.
A complete example is as follows (source):
#include <assert.h>
#include <GL/glut.h>
#include <GL/glext.h>

static int list;

static void
reshape(int width, int height)
{
  glViewport(0, 0, width, height);
 
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0, width, 0, height, -1.0, 100.0);

  assert(glGetError() == GL_NO_ERROR);
}

static void
init(void)
{
  list = glGenLists(1);

  glNewList(list, GL_COMPILE);
  glBegin(GL_TRIANGLES);
    glColor3d(100.0, 0.0, 0.0);
    glVertex3d(0.0, 0.0, 0.0);
    glColor3d(0.0, 100.0, 0.0);
    glVertex3d(100.0, 0.0, 0.0);
    glColor3d(0.0, 0.0, 100.0);
    glVertex3d(100.0, 100.0, 0.0);
  glEnd();
  glEndList(); 
}

static void
display(void)
{
  glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
  glClear(GL_COLOR_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glPushMatrix();
  glTranslated(20.0, 20.0, 0.0);
  glCallList(list);
  glTranslated(120.0, 120.0, 0.0);
  glCallList(list);
  glPopMatrix();

  glutSwapBuffers();
}

int
main(int argc, char **argv)
{
  glutInit(&argc, argv);
  glutCreateWindow("Display list triangle");
  init();
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);
  glutIdleFunc(glutPostRedisplay);

  glutMainLoop();
  return 0;
}

      
As can be seen from the output, the triangle drawing commands are compiled into a display list and then called twice to draw two triangles. The commands in the display list were typically stored in the OpenGL implementation's memory in order to reduce the number of commands sent between the program and the OpenGL driver. Display lists were obviously not a solution to the general inefficiencies of the immediate mode.

PreviousUpNext
2. Immediate modeA Brief History Of Vertex Specification In OpenGL 4. Vertex Arrays