rewriting glList problem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

rewriting glList problem

Tomek
Hi!
I have a bit of a problem with glLists in JOGL2. If someone could give me some advice i would be very grateful!
I have a project where I have to load a single model and then be able to load a different model replacing the first one.
Here's the function i use to load a model:

        public void loadModel(final GeometricModel geometricModel) {

                if (Threading.isOpenGLThread())
                        glLoadModel(geometricModel);
                else
                        Threading.invokeOnOpenGLThread(new Runnable() {
                                @Override
                                public void run() {
                                        glLoadModel(geometricModel);
                                }
                        });
        }
Here's the function i use to load a model into a glList:

    private void glLoadModel(GeometricModel geometricModel) {
                if (gl.glIsList(GL_DRAW_WIRED))
                        gl.glDeleteLists(GL_DRAW_WIRED, 2);
                GL_DRAW_WIRED = gl.glGenLists(2);
                GL_DRAW_FACED = GL_DRAW_WIRED + 1;
                geometricModel.drawWired(gl, colorRedE, colorGreenE, colorBlueE);
                gl.glEndList();
                gl.glNewList(GL_DRAW_FACED, GL2.GL_COMPILE);
                geometricModel.drawFaces(gl, colorRedF, colorGreenF, colorBlueF);
                gl.glEndList();
        }

In the first function, i check if I'm in OpenGL thread because i only load the model from the openGL thread the first time. Every next model is loaded from a different thread.
Anyway... Here's the problem... When running from OpenGL thread directly, everything works normal, but when I try to load a second model from Runnable, gl.glIsList(GL_DRAW_WIRED) returns false and gl.glGenLists(2) returns 0 which indicates some sort of a problem. But i cought no glErrors after that command.

So basically, my question is: what's the difference between running directly from OpenGL thread and trough Runnable? I guess this has more to do with AWT events then anything but i can't seem to figure it out. Please help :(
Reply | Threaded
Open this post in threaded view
|

Re: rewriting glList problem

gouessej
Administrator
You have to make the OpenGL context current, not only to call a runnable on the OpenGL thread.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: rewriting glList problem

Tomek
wow, that worked!
Thanks a lot!
Reply | Threaded
Open this post in threaded view
|

Re: rewriting glList problem

gouessej
Administrator
Don't forget to release the context once you don't need it anymore. You're welcome.
Julien Gouesse | Personal blog | Website