Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
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…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

636 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