PDA

View Full Version : Display lists and matrix operations



ben
11-19-2001, 12:28 PM
If I record a display list using something similar to the code below and then execute the list many times, do the translate and rotate operations (as well as the push and pop) occur on each call? Am I better off transforming the vertices of the primitive myself and recording the transformed vertices in a display list? This would avoid the push, rotate, translate and pop operations.

glNewList( listid, GL_COMPILE);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glTranlslated(1.0, 2.0, 3.0);
glRotated(45.0, 0.0, 0.0, 1.0);

< Draw something >

glPopMatrix();

glEndList();

Bob
11-20-2001, 02:27 AM
Almost every OpenGL command will be compiled into the list. That includes matrix operations. You can transform the vertices yourself, and skip all matrix commands, but if you have alot of stuff to draw in the list, you won't notice any difference in performance. And you probbaly won't even though you aren't drawing that much.

ben
11-20-2001, 10:30 AM
Really? In the scenario that I have, I thought it might be more efficient to transform the vertices myself.

I am going to be drawing, for instance, force arrows on vertices in my model. The arrows themselves will consist of a conical head and a line for a tail. My original thought was to draw the head and tail oriented along the z-axis. Then, I would use the glRotate and glTranslate functions to draw each arrow where it needs to be. I would capture all of the arrows into one big display list and simply call the big display list whenever I wanted to draw the arrows. The code would look something like:

glNewList( allArrowsListId, GL_COMPILE);

glMatrixMode(GL_MODELVIEW);
for( each arrow )
{
glPushMatrix();
glTranslated( the position of the arrow);
glRotate( the orientation of the arrow);
glCallList( id of arrow list );
glPopMatrix();
}

glEndList();


The alternative would be to do something like:

glNewList( allArrowsListId, GL_COMPILE);

glMatrixMode(GL_MODELVIEW);
for( each arrow )
{
glBegin(GL_TRIANGLES);
// Execute vertices and normals
// the head.
glEnd();

glBegin(GL_LINES);
// Execute two vertices for the tail
glEnd();
}

glEndList();

I guess it boils down to which is more expensive: The pushing/popping of the modelview matrix and the matrix operations or the execution of the individual vertices.