Rendering from other threads

I am experimenting with SDL… trying to integrate it with our current
system because…well… it’s cool, and I’d love to go tell some other
vendors to take a hike. Specifically, my project integrates ODE (Open
Dynamics Engine) and SDL.

That said, I’m running into what I hope is a simple problem… when ever I
render a screen from some other thread, other than the main one, I get a
"gray" screen. It does this when I call SDL_GL_SwapBuffers(). Note that I
am not using SDL_CreateThread()… I can’t because of some other
requirements. I even tried _beginthread().

Our normal model is for the main thread to go to sleep after spawning
threads to 1) Handle Rendering, 2) Handle dynamics and 3) Handle user
events. The user event thread goes to sleep until… well, a user event,
but the other two are fairly active, using various symaphoring objects to
sync things. Still, I’ve stripped all this down… for the purpose of
testing… to just a main thread and a render thread with not much going on.

Any thoughts?

Jerry L.Holmes
@Jerry_L_Holmes
Mammoth Effects (MFX)
http://www.mammothfx.com

That said, I’m running into what I hope is a simple problem…
when ever I
render a screen from some other thread, other than the main
one, I get a
"gray" screen. It does this when I call SDL_GL_SwapBuffers().
Note that I
am not using SDL_CreateThread()… I can’t because of some other
requirements. I even tried _beginthread().

I just can add my experience, I don’t know a real solution…

We use OpenGL with threads in a GLUT-based application (no SDL),
and at least in this case it seems that OpenGL functions work
only in the thread that has initialized GLUT. Trying to call
OpenGL from another threads resulted in various kinds of strange
behaviour.

According to OpenGL specs, it should be safe to use OpenGL calls
from multiple threads but no more than one thread can use the
same OpenGL context at the same time. This may, possibly, be the
problem - because SDL has only one application screen, it
probably uses only one OpenGL context and does not release it,
therefore it stays owned by the main thread. But that’s only my
theory, I didn’t read the source (yet)…

Have a nice day, and lotsa sunshine!

Sincerely,

 Jiri "BlueBear" Dluhos

Objevte oran?ov? sv?t financ? a vyhrajte v sout??i s ING!
http://user.centrum.cz/redir.php?url=http://soutez.ing.cz

I am experimenting with SDL… trying to integrate it with our current
system because…well… it’s cool, and I’d love to go tell some other
vendors to take a hike. Specifically, my project integrates ODE (Open
Dynamics Engine) and SDL.

That said, I’m running into what I hope is a simple problem… when ever I
render a screen from some other thread, other than the main one, I get a
"gray" screen. It does this when I call SDL_GL_SwapBuffers(). Note that I
am not using SDL_CreateThread()… I can’t because of some other
requirements. I even tried _beginthread().

As was mentioned in the other message, you can’t really do graphics calls
from other than the main thread.

I recommend that you perform event and graphics updates in the main thread
and if you need to be multi-threaded, put the simulation in another thread.
If you really need three threads, it’s safe to handle user events in another
thread, as long as you call SDL_PumpEvents() in the graphics thread to run
the windows message pump.

I have heard rumors about an extension to WGL which allows you to "bind"
a GL context to a particular thread, but I haven’t tried it myself, and
it’s not portable to other operating systems.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

I don?t know that for sure, but GLX has this feature, too (I ?ve never used
GLX directly).

It seems that you can assign a OpenGL context to the calling thread with
glXMakeCurrent.
See also: http://www.cevis.uni-bremen.de/~uwe/opengl/glXMakeCurrent.htmlOn Tuesday 16 October 2001 17:17, Sam Lantinga wrote:

I have heard rumors about an extension to WGL which allows you to "bind"
a GL context to a particular thread, but I haven’t tried it myself, and
it’s not portable to other operating systems.


Johannes Schmidt

< http://libufo.sourceforge.net > Your widget set for OpenGL

Ack! So obvious! You hit the nail right on the head. It works fine now.
My thanks.> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
dluhosj at centrum.cz
Sent: Tuesday, October 16, 2001 7:49 AM
To: sdl at libsdl.org
Subject: re: [SDL] Rendering from other threads

That said, I’m running into what I hope is a simple problem…
when ever I
render a screen from some other thread, other than the main
one, I get a
"gray" screen. It does this when I call SDL_GL_SwapBuffers().
Note that I
am not using SDL_CreateThread()… I can’t because of some other
requirements. I even tried _beginthread().

I just can add my experience, I don’t know a real solution…

We use OpenGL with threads in a GLUT-based application (no SDL),
and at least in this case it seems that OpenGL functions work
only in the thread that has initialized GLUT. Trying to call
OpenGL from another threads resulted in various kinds of strange
behaviour.

According to OpenGL specs, it should be safe to use OpenGL calls
from multiple threads but no more than one thread can use the
same OpenGL context at the same time. This may, possibly, be the
problem - because SDL has only one application screen, it
probably uses only one OpenGL context and does not release it,
therefore it stays owned by the main thread. But that’s only my
theory, I didn’t read the source (yet)…

Have a nice day, and lotsa sunshine!

Sincerely,

 Jiri "BlueBear" Dluhos

Objevte oran?ov? sv?t financ? a vyhrajte v sout??i s ING!
http://user.centrum.cz/redir.php?url=http://soutez.ing.cz


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Each thread must have its OpenGL context.
You then call wglMakeCurrent (), pretty much like in
GLX,

Paulo> ----- Original Message -----

From: sdl@myrealbox.com (Johannes Schmidt)
To:
Sent: Tuesday, October 16, 2001 5:23 PM
Subject: Re: [SDL] Rendering from other threads

On Tuesday 16 October 2001 17:17, Sam Lantinga wrote:

I have heard rumors about an extension to WGL which allows you to "bind"
a GL context to a particular thread, but I haven’t tried it myself, and
it’s not portable to other operating systems.

I don?t know that for sure, but GLX has this feature, too (I ?ve never
used
GLX directly).

It seems that you can assign a OpenGL context to the calling thread with
glXMakeCurrent.
See also: http://www.cevis.uni-bremen.de/~uwe/opengl/glXMakeCurrent.html


Johannes Schmidt

< http://libufo.sourceforge.net > Your widget set for OpenGL


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl