using OpenGL in multiple threads

When i use opengl in another thread then the one in which it is created my screen wont update. Does anyone know why?

You’re probably not calling MakeCurrent to make the GL rendering context current to the new thread.

I have tried to use the wglMakeCurrent function but i’m still not getting any output to the screen.

You can only use gl commands from the same thread as created the rendering context.

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.

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.

Thancks guys for your help. I didn’t release the rendering context in the first Thread. Got it working now. Thanks again.

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.

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). 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.

How do you create your thread ?
If you want to use the C run time library, you must use _beginthreadex instead of _beginthread.

Originally posted by Rob Lemmens:
[b]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.[/b]

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

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…