






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







1
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
5
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
Managing Display List Indices listIndex=glGenLists(1); if(listIndex!=0) { glNewList(listIndex,GL_COMPILE); ... glEndList(); } 11 List Indices can be automatically generated: