![Page 1: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/1.jpg)
MAE152
Computer Graphics for Scientists and Engineers
Fall 03
Display Lists
![Page 2: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/2.jpg)
Objective
• Understand how display lists can be used along with commands in immediate mode to organize your data and improve performance.
• Maximize performance by knowing how and when to use display lists.
![Page 3: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/3.jpg)
What is Display List
• Display list is a group of OpenGL commands that have been stored for later execution.
• When a display list is invoked, the commands in it are executed in the order in which they were issued.
• Immediate mode– commands are executed immediately
• You can freely mix immediate mode programming and display lists.
![Page 4: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/4.jpg)
Immediate Mode versus Display Lists
Display Listed
Immediate Mode
DisplayList
PolynomialEvaluator
Per VertexOperations &
PrimitiveAssembly
RasterizationPer Fragment
Operations
TextureMemory
CPU
PixelOperations
FrameBuffer
![Page 5: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/5.jpg)
Immediate Mode vs Display Listed Rendering
• Immediate Mode Graphics– Primitives are sent to pipeline and displayed right away– No memory of graphical entities
• Display Listed Graphics– Primitives placed in display lists– Display lists kept on graphics server– Can be redisplayed with different state– Can be shared among OpenGL graphics contexts
![Page 6: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/6.jpg)
Why Use Display Lists?
• It can reduce OpenGL command transmission– When running OpenGL programs remotely to another
machine on the network. Display lists are stored in server computer. You can reduce the cost of repeatedly transmitting commands over the network.
• Performance Gain in Local Running– Some graphics hardware may store display lists in
dedicated memory or may store the data in an optimized form that is more compatible with the graphics hardware or software.
![Page 7: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/7.jpg)
A Simple Example
void init(void) {
GLuint theTorus = glGenLists(1);
glNewList(theTorus, GL_COMPILE);
torus(8, 25)
glEndList();
}
void display(void) {
glCallList(theTorus);
glFlush();
}
![Page 8: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/8.jpg)
A Simple Example (cont)
void torus(int numc, int numt) {
for(i=0; i<numc; i++) {
glBegin(GL_QUAD_STRIP);
for(j=0; j<=numt; j++) {
for(k=1; k>=0; k--) {
x = (1+.1*cos(s(twopi/umc))*cos(t*twopi/numt);
y = (1+.1*cos(s(twopi/umc))*sin(t*twopi/numt);
z = .1 * sin(s*twopi/numc);
}
}
glEnd();
}
}
![Page 9: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/9.jpg)
• Demo• Display List for Triangles
![Page 10: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/10.jpg)
Display-List Design Philosophy
• Display list can not be changed.– this is to MAXIMIZE the performance gain.
• Display list stores only the final values.– does NOT store the intermediate results– Ex) glRotate*() directly stores the matrix– Ex) when the material properties are changed f
or each item– Ex) when dealing with textures
![Page 11: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/11.jpg)
Naming a Display List
• Each display list is identified by an integer index.
• To allocate one or more unused index, use glGenLists() command.– listIndex = glGenLists(n); allo
cates n consecutive previously unallocated display-list indices, and returns the first index.
![Page 12: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/12.jpg)
Creating a Display List
• Use glNewList() and glEndList()
glNewList(listIndex, GL_COMPILE);
...
glEndList();
• Options for glNewList()– GL_COMPILE_AND_EXECUTE– GL_COMPILE
![Page 13: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/13.jpg)
What’s Stored in a Display List
• Almost all OpenGL commands can be stored in a display list.
• Only the values for expressions are stored in the list.
GLfloat v[3] = {0, 0, 0};
glNewList(1, GL_COMPILE);
glColor3fv(v);
glEndList();
v[0] = 1.0; // no effect
![Page 14: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/14.jpg)
Executing a Display List
• Use glCallList() command to execute commands in a display list.
void display(void {glCallList(theTorus);
glFlush();
}
![Page 15: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/15.jpg)
Display Lists and Hierarchy
• Consider model of a car– Create display list for chassis– Create display list for wheel
glNewList( CAR, GL_COMPILE );glCallList( CHASSIS );glTranslatef( … );glCallList( WHEEL );glTranslatef( … );glCallList( WHEEL );
…glEndList();
![Page 16: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/16.jpg)
Hierarchical Display List
• Hierarchical display list is a display list that includes other display lists in it.
• Limit on the nesting = 64
glNewList(listIndex, GL_COMPILE);
glCallList(frame);
glTranslatef(1.0, 1.0, 0.0);
glCallList(wheel);
glEndList();
![Page 17: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/17.jpg)
Managing Display List Indices
• Use glIsList() command to determine whether a specific index is in use.
GLboolean glIsList(GLuint list)
• Use glDeleteLists() command to delete a contiguous range of display lists.
glDeleteLists(list, n)
deletes n display lists, starting at the index specified by list.
![Page 18: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/18.jpg)
Executing Multiple Display Lists
• Use glListBase() command to set base index of glCallLists()
glListBase(base)
• Use glCallLists() command to execute multiple display lists.
glCallLists(n, type, lists)
executes n display lists. See the next example.
![Page 19: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/19.jpg)
An Example
void display()
{
glListBase(10);
GL_INT lists[] = { 1, 1, 3, 5 };
glCallLists(4, GL_INT, lists);
}
// Executed display lists are of
// index 11, 12, 15, 20
![Page 20: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/20.jpg)
Managing State Variables
• You can not use glGet*() in a display list.
– glGetFloatv(GL_CURRENT_COLOR, &v[0])
• Instead, use glPushAttrib() command to save a group of state variables.
• Use glPopAttrib() to restore the values when you’re ready for them.
How to include state changes in display lists?
![Page 21: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/21.jpg)
Managing State Variables
glNewList(listIndex, GL_COMPILE); // Example code.
glPushMatrix(); // Save current matrix
glPushAttrib(); // Save current attribute
glColor3f(1.0, 0.0, 0.0); // Attribute change
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); // Matrix change
glPopAttrib(); // Restore attribute
glPopMatrix(); // Restore matrix
glEndList();
![Page 22: MAE152 Computer Graphics for Scientists and Engineers Fall 03 Display Lists](https://reader036.vdocuments.mx/reader036/viewer/2022062423/568147b5550346895db4fb72/html5/thumbnails/22.jpg)
End of Display List