Display Lists sometimes work, sometimes don't, depending on when created.

Posted on 2004-09-02
Medium Priority
Last Modified: 2013-12-06
I'm creating a game in gl4java, and I am trying to make use of display lists because there are several large models in use.  The GLAnimCanvas, when the program starts, is not visible; it's actually part of a tabbed panel, and the *other* tab is visible from the start (it's a 2D representation of the screen, using something other than OpenGL).  Even though I call canvas.start() when the program loads, none of the init/preInit/display functions are called because it is not visible, only when I switch to the OpenGL tab do these functions get called for the first time (but on subsequent tab changes, they do not get called again-- just once).  

My problem:  On the 2D side, I place my objects (planes, tanks, etc.), and then I have the ability to view them in the OpenGL side.  Any objects I place *before* I go to the 3D side for the first time seem to work fine.  The first time they are rendered, I check to see if the display list has been compiled, if so I render (glCallList), if not, i compile.  However, if I go to the 3D side, and then choose to place a model on the 2D side that i haven't yet placed, when I go back to the 3D (opengl) side, they do not show up, however the display list *is* compiled and the glCallList call *is* executed.  It's almost as if after a few calls to display() that any display list compiled is not valid: if i place an object before display() is ever called, then it will be compiled on the *very first* call to display and will consequently render properly; if, however, i switch to the 3D side (therefore causing display() to be called many times) and *then* compile display lists, they don't show up.

Any ideas?  I'm not exactly sure what glGenLists() does; could this have something to do with it?
Question by:slikrik98
  • 3
  • 2
LVL 17

Accepted Solution

davebytes earned 500 total points
ID: 11965499
Once again, google is your friend -- you can look up the definition of any OpenGL function pretty quickly:

Two samples:

glGenLists works like many other GL functions, in that you tell it a 'count', and it 'allocates' that many indices for you to use.

You must call it to 'create' a display list index for later use.  You can call it like:
GLuint dlIndex;
dlIndex = glGenLists(1);

That sets dlIndex to whatever the starting available index is.  If you had already allocated a few, it might be '4' or '5'.

You can also allocate a block at a time:
dlIndex = glGenLists(64);

say dlIndex comes back as '5', you have 64 indices starting at the number 5, ending with the number 68.

YOU need to keep track of all indices 'created' and make sure to destroy them the same way.  Look at the second sample I gave, it'll help some.


Author Comment

ID: 11965953
Makes sense, and I'm now using it correctly (I think), however here's what's happening:

If I switch to the 3D tab (and thus start the GLCanvas running) before I add any display lists, glGenLists always returns 0 (and they thus don't show up).  If, however, I place the models in the system *before* kicking off the GL canvas, glGenLists returns 1, 2, 3, ... and so on, as it should (and they show up).

Why won't it allow me to allocate the space for the indices after the canvas has started?

Author Comment

ID: 11968467
Now i'm just getting incredibly bizarre behavior (most likely a result of the memory allocation for the display lists);  I found one problem that might have been the cause of the 0 return value from genLists, I didn't have my gljMakeCurrent call before this was occuring.  However, even now that it allocates space (in other words, glGenLists is returning nonzero values), the models sometimes don't appear and the program crashes (saying abnormal runtime error, or something along these lines).  I'm beginning to think that maybe my display() function is being called from two sources, because I vaguely remember a problem i used to have before where this occured.  Is it possible that two threads are calling the display function?  how would I know if there are 2 glContexts created?  my main loop looks like this:

public void display()
            glj.gljMakeCurrent();      //Ensure GL is initialised correctly
            gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glj.gljSwap();             //Swap buffers
            glj.gljFree();             // release GL

I've implemented a scene graph and root is the root node of the graph, so my traverseRender function basically traverses the graph and renders each node.  I'm wondering if someone else is calling display while i'm in the traverseRender() function and so gljMakeCurrent is called before the previous gljFree() was called.  Just so you know, when each object in the graph gets rendered, it firsts looks to see if a display list has been created for that type, if so, it just calls the display list, if not, it compiles the display list.
LVL 17

Expert Comment

ID: 11976566
Yes, you need to have GL established and a context current when making any GL calls that allocate structures attached to a context..

That code looks okay by me.  If display is re-entrant, that'd be a potentially huge problem.  I don't know enough about Java usage in this situation -- I'm a GL expert, not a Java one. ;)

If you don't compile the display lists, and just use the raw data, does everything work fine?


Author Comment

ID: 11977650
I made the switch to JOGL, and everything works fine.  I couldn't handle not having full control over the display method (and when it was called); I'm sure my problems were a result of sloppy code, and not gl4java's fault, but it's a lot easier to write sloppy code when using it.

Thanks for your help.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question