Solved

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

Posted on 2004-09-02
5
303 Views
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?
0
Comment
Question by:slikrik98
  • 3
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
davebytes earned 125 total points
Comment Utility
Once again, google is your friend -- you can look up the definition of any OpenGL function pretty quickly:
http://www.cs.bham.ac.uk/resources/ums/OpenGL/man/glGenLists.html

Two samples:
http://www.lighthouse3d.com/opengl/displaylists/index.php3?5
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=13

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.

-d
www.chait.net
0
 

Author Comment

by:slikrik98
Comment Utility
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?
0
 

Author Comment

by:slikrik98
Comment Utility
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);
            gl.glPushMatrix();
            gl.glLoadIdentity();
           
            positionCamera();
            traverseRender(root);
           
            gl.glPopMatrix();            
            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.
0
 
LVL 17

Expert Comment

by:davebytes
Comment Utility
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?

-d
0
 

Author Comment

by:slikrik98
Comment Utility
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.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
BundleID & an app record on iTunes connect 2 661
candy crush 4 422
Network game - UDP safety concerns? 10 256
Is an Indie RTS practical? 7 112
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…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

18 Experts available now in Live!

Get 1:1 Help Now