LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: tomjnsn on May 31, 2005, 21:52:44

Title: Threading
Post by: tomjnsn on May 31, 2005, 21:52:44
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
Title: Threading
Post by: Matzon on May 31, 2005, 22:04:23
you should be fine using another thread than main. Just stick to 1 thread.
Title: Threading
Post by: blazko on September 15, 2005, 21:06:24
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
Title: Threading
Post by: Matzon on September 15, 2005, 22:31:44
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();
Title: Threading
Post by: blazko on September 15, 2005, 22:42:55
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