I have got some code like that
glNewList(displist_boxy, GL_COMPILE);
for(int i=0; i<scene_max; i++)
{
DrawAABox( sceneGL[i].x,
sceneGL[i].y,
sceneGL[i].z,
10,10,10
);
}
glEndList();
DrawAABox draws 6 quad axis aligned box ( with glBegin glNormal GlVertexx… glEnd)
It work in immediate mode but when I try to build a disoplay list as above,
then call the list it has no effect (no boxes are drawed) Should it work or this just should not work (I do not know much abut it )
A display list distills all OpenGL operations done inside the
glNewList/glEndListblock into a constant set of commands that are then executed when calling the display list (withglCallList). This means every “dynamic” code inside the list creation is, well, compiled into the list. So when called your box will use whatever positionsceneGL[i]had when you built the list. In fact you will only have a constant number of boxes, that is whatever numberscene_maxwas when building the list. So if you do this in initialization code, wherescene_maxmight be0, nothing will be drawn.Think about it, what could the driver possibly do when building this list? Just record all OpenGL commands called (and maybe convert them into some compressed and optimized format) for later submission or magically take the executed machine code (and its whole surrounding context) from your final executable when run and store this somehow to recall every operation you did between
glNewList/glEndList(which wouldn’t be much of a performance boost when compared to just executing it immediately, anyway)?EDIT: As a side note, rather prefer the use of VBOs for pre-recording of geometry, which compared to display lists might loose some features, like state change recording, but give you others, like dynamic data updates. Likewise the implementation of display lists is totally up to the implementation and might not be faster than VBOs and the like. Likewise they’re deprecated (which might also speak for lousy/slow implementations on modern hardware, because drivers don’t tend to optimize rarely used paths that well).