PDA

View Full Version : using OpenGL in multiple threads



Rob Lemmens
09-25-2002, 06:05 AM
When i use opengl in another thread then the one in which it is created my screen wont update. Does anyone know why?

Asgard
09-25-2002, 06:14 AM
You're probably not calling MakeCurrent to make the GL rendering context current to the new thread.

Rob Lemmens
09-25-2002, 06:29 AM
I have tried to use the wglMakeCurrent function but i'm still not getting any output to the screen.

ToolTech
09-25-2002, 06:40 AM
You can only use gl commands from the same thread as created the rendering context.

Bob
09-25-2002, 06:48 AM
You can call OpenGL functions from any thread, as long as it's from the thread that has the rendering context. You can move the rendering context between threads if you want.

ToolChest
09-25-2002, 06:51 AM
You can share a context with multiple threads you just need to make sure you call glMakeCurrent with a NULL context when a thread is finished with the context. Other wise the next thread will call glMakeCurrent and it will fail because the context is still bound to the last thread.

John.

Rob Lemmens
09-25-2002, 08:11 AM
Thancks guys for your help. I didn't release the rendering context in the first Thread. Got it working now. Thanks again.

Rob Lemmens
09-25-2002, 09:11 AM
hmmm, the app seemed to work but i'm getting really wierd errors... something about a illegal instruction in PMX2OGL.DLL at 0xc000001D... is this because of the multithreading? Someone once told me that OpenGL is unstable in a multithreaded app is this true??

btw Does anyone know a good article about openGL in a multithreaded app? I can't find anything.

ToolChest
09-25-2002, 09:31 AM
Opengl works great in multithreaded apps, you just need to be careful with your code. Make sure all of your gl calls are made between the calls to grab and release the context. Also test the calls to glMakeCurrent, if the call fails throw an exception. If your code is not centralized your going to find yourself having lots of problems. Opengl is great when you don’t need to worry about the context state, when you do you suddenly realize how messy your code is (opengl call in every class and function). http://www.opengl.org/discussion_boards/ubb/smile.gif I know I recently moved to a multithreaded render model, but it is worth it. Opengl is very fast if you synchronize you workload properly…

John.

opla
09-25-2002, 09:34 AM
How do you create your thread ?
If you want to use the C run time library, you must use _beginthreadex instead of _beginthread.

V-man
09-26-2002, 05:20 AM
Originally posted by Rob Lemmens:
hmmm, the app seemed to work but i'm getting really wierd errors... something about a illegal instruction in PMX2OGL.DLL at 0xc000001D... is this because of the multithreading? Someone once told me that OpenGL is unstable in a multithreaded app is this true??

btw Does anyone know a good article about openGL in a multithreaded app? I can't find anything.

I've seen that kind of error before. You should trace it to what instruction it is pointing to. What's your OS, card +driver version?

V-man

pATChes11
09-26-2002, 11:29 AM
That looks like it's a Permedia series card, and it might be the Permedia 2. I've messed with getting one to work before for a friend of mine... and it's well worth the $40 it would take to just get a GF2 or something. Even that would be a HUGE upgrade...