Threading

Started by tomjnsn, May 31, 2005, 21:52:44

Previous topic - Next topic

tomjnsn

I know that you're not supposed to use openGL in anything more than a single thread, but I'm wondering if I could move the whole thing over into my own separate thread, instead of the default thread? I'm using lwjgl for an app that I have multiple monitors, where there is an interface that the user utilizes on one monitor and the other monitor shows specific animations, etc.  I would think of something like this:

public class DisplayThread extends Thread {

    public void run() {

        Display.create();

        while (true) {

            // do drawing
            Display.update();

        }

        Display.destroy();

    }
}


Would that work or would I have some extra wierdness that I'd have to deal with?

I know working in Swing/AWT stuff you ALWAYS are supposed to do things on their thread, but isn't the Display actually something separate from Swing/AWT, or does it have to live within that realm?

Thanks,

Tom

Matzon

you should be fine using another thread than main. Just stick to 1 thread.

blazko

Hello all,

Due to arch reasons of my project, I tried to pack all OpenGL stuff into a dedicated thread - guaranteeing that all OpenGL calls come from that same thread.
However, when I call very simple OpenGL functions I get a null pointer exception. When I call them form main() and not from a dedicated thread, it works. The exception e.g. happens in glClear() when GLContext is accessed, I think; according to a stack trace, this is the line:

public static void glClearColor(float red, float green, float blue, float alpha) {

		long function_pointer = GLContext.getCapabilities().GL11_glClearColor_pointer;

...


So, what may be wrong? What do I have to think of in multi-threaded apps in aspect of LWJGL.

Thanks for any hints,
Timo
oing Java on GNU/Linux 2.6.10 (Ubuntu) - nVidia GeForce 6800GT@Ultra

Matzon

you need to make sure that the thread that creates the display is the one doing all the ogl. Alternatively you need to make its context current by calling makeCurrent();

blazko

Hello Matzon,

Yeah, that was it: I encapsulated all GL stuff into an own class that got assigned to the thread after its creation thru Spring. So, now I call an init method just in thread's run(), so that I make shurethat Display.create() is called in the right place.

Thank you for your quick reply!
Greetings to Denmark,
Timo
oing Java on GNU/Linux 2.6.10 (Ubuntu) - nVidia GeForce 6800GT@Ultra