Docsity

Display List - Computer Graphics - Lecture Slides, Slides of Computer Graphics

Partial preview of the text

Download Display List - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!

1

Introduction

  • A display list is a group of OpenGL commands that

have been stored for later execution.

  • Most OpenGL commands can be either stored in a

display list or issued in immediate mode.

2 For example, suppose you want to draw a circle with 100 line segments drawCircle() { GLint i; GLfloat cosine, sine; glBegin(GL_POLYGON); for(i=0;i<100;i++){ cosine=cos(i2PI/100.0); sine=sin(i2PI/100.0); glVertex2f(cosine,sine); } glEnd(); }

4

  • Draw the circle once and have OpenGL remember how to draw it for later use. #define MY_CIRCLE_LIST 1 buildCircle() { GLint i; GLfloat cosine, sine; glNewList (MY_CIRCLE_LIST, GL_COMPILE); glBegin(GL_POLYGON); for(i=0;i<100;i++){ cosine=cos(i2PI/100.0); sine=sin(i2PI/100.0); glVertex2f(cosine,sine); } glEnd(); glEndList (); } MY_CIRCLE_LIST is an integer index that uniquely iden- tifies this display list. You can execute the display list later with this glCallList() command: glCallList(MY_CIRCLE_LIST);

5

  • A display list contains only OpenGL calls.
  • The coordinates and other variables are evaluated and copied into the display list when the list is compiled.
  • You can delete a display list and create a new one, but you can’t edit an existing display list.
  • Display lists reside with the server and network traffic is minimized. Matrix computations, lighting models, textures, etc.
  • Display List disadvantages: large storage; immutability of the contents of a display list.

7 void display(void) { GLuint i; glClear (GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); for (i = 0; i < 10; i++) glCallList (listName); drawLine (); / color red; affected by the 10 translate / glFlush (); } Constants are stored and won’t change GLfloat color_vector[3]={0.0,0.0,0.0}; glNewList(1,GL_COMPILE); glColor3fv(color_vector); glEndList(); color_vector[0]=1.0; // color will be black if you use the display list

8 glNewList(listIndex,GL_COMPILE); glPushMatrix(); glPushAttrib(GL_CURRENT_BIT); glColor3f(1.0, 0.0, 0.0); glBegin(GL_POLYGON); glVertex2f(0.0,0.0); glVertex2f(1.0,0.0); glVertex2f(0.0,1.0); glEnd(); glTranslatef(1.5,0.0,0.0); glPopAttrib(); glPopMatrix(); glEndList(); The code below would draw a green, untranslated line. void display(void) { GLint i; glClear (GL_COLOR_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); for (i = 0; i < 10; i++) glCallList (listIndex); drawLine (); glFlush (); } Use glPushAttrib() to save a group of state variables and glPopAttrib() to restore

1 0 Editable Display Lists

  • Example editable display list: To render the polygon, call display list number 4. To edit a vertex, you need only recreate the single display list corresponding to that vertex. glNewList(1,GL_COMPILE); glVertex3f(v1); glEndList(); glNewList(2,GL_COMPILE); glVertex3f(v2); glEndList(); glNewList(3,GL_COMPILE); glVertex3f(v3); glEndList(); glNewList(4,GL_COMPILE); glBegin(GL_POLYGON); glCallList(1); glCallList(2); glCallList(3); glEnd(); glEndList();

Managing Display List Indices listIndex=glGenLists(1); if(listIndex!=0) { glNewList(listIndex,GL_COMPILE); ... glEndList(); } 11 List Indices can be automatically generated: