PDA

View Full Version : display lists and modelling transformation



anpu
03-01-2005, 11:56 AM
According to the OpenGL Programming Guide V1.4 display lists should be able to handle modelling transformations and such. However I experience something very different, but probably there is just a stupid bug in my code.

I want to draw graphs, that is a heap of dots and lines, or to let it appear more nicely a heap of spheres and cylinders. So I have a variable number of spheres representing my vertices (of my graph not of an OpenGL thing) and cylinders for edges. For both sphere and cylinder I have a display list and then I simply do all the transformations so the spheres and cylinders appear in all the right places. So far so good.

However if I put all this, obviously together with the modelling transformations, into another display list, things get messed up. All I see is a single sphere (or probably more correct: n spheres all exactly on top of each other, and no cylinder as it is inside the sphere). Basically what I see is the same as if there would have been no modelling transformations.
Why is that?

Here's my code:
function draw_cubes() {
GLint cubelist;
cubelist=glGenLists(1);

glNewList(cubelist,GL_COMPILE);
cube->opengl_draw_solid(); //draws one cube
glEndList();
delete cube;

for (pre_opengl_object<pre_opengl_vertex>* vertex=v.first(); vertex!=0; vertex=vertex->next) {
glPushMatrix();
glTranslated(vertex->item->x(),vertex->item->y(),vertex->item->z());
glCallList(cubelist);
glPopMatrix();
}
glDeleteLists(cubelist,1);
}

somesub() {
glNewList(x,GL_COMPILE)
draw_cubes();
glEndList();
}

someothersub() {
draw_cubes(); //works
glCallList(x); //doesn't work

Relic
03-01-2005, 11:20 PM
Multiple problems:
1.) It's not allowed to call glNewList while you are in display list compile mode. If you added a glGetError after the glEndLists you would have noticed.
2.) If you did it correctly, the hierarchical glCallList inside draw_cubes would be included in the root display lists. You cannot expect that to draw soemthing if you call glDeleteLists for the inner display list. glGenLists and glDeleteLists are immediately executed and not compiled into a display list!
3.) Generating a display list for single usage is a complete waste of time.