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

Posted on 2004-09-02
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 125 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating an Android APP / Iphone APP for a beginner having a windows machine 1 348
Software to create cartoons/animations 2 351
old35  java challenge 4 130
bunnyEars challenge 6 118
What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now