Reputation: 1370
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 )
Upvotes: 0
Views: 1830
Reputation: 45948
A display list distills all OpenGL operations done inside the glNewList/glEndList
block into a constant set of commands that are then executed when calling the display list (with glCallList
). This means every "dynamic" code inside the list creation is, well, compiled into the list. So when called your box will use whatever position sceneGL[i]
had when you built the list. In fact you will only have a constant number of boxes, that is whatever number scene_max
was when building the list. So if you do this in initialization code, where scene_max
might be 0
, 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).
Upvotes: 2
Reputation: 162164
To create a display list, you must have your target OpenGL context being created and bound first. If you happen to initialize the display list in code that's called before there's a/the OpenGL context nothing will show up later.
Also what Christian Rau told you in https://stackoverflow.com/a/13192138/524368
On a side note: You should not be using Display lists at all. They've been deprecated for about 10 years (OpenGL-2 was originally planned to do away with display lists) and OpenGL-3 followed through to it a half a decade later.
Use VBOs and VAOs instead.
Upvotes: 1
Reputation: 7397
You seem to miss generating of UID for displist_boxy
variable. Here's how it should look.
coAxis := glGenLists(1);
glNewList(coAxis, GL_COMPILE);
glBegin(GL_TRIANGLES);
...
glEnd;
glEndList;
Usage is as follows:
glCallList(coAxis);
Upvotes: 1