Sdl && opengl - threading problems

Hi All,

When I move my display code into a thread, it’s broken.
minimal broken thread code :------------

void drawscreen() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
SDL_GL_SwapBuffers( );
}

int DisplayThread(void *ignore) {
while (!quitapplication) {
SDL_mutexP(breach_mutex);
drawscreen();
SDL_mutexV(breach_mutex);
}
return 0;
}


the thread creation works fine, if I add “printf”'s the the stdout inside
"drawscreen()"
they are displayed.
If i remove the thread creation code, and put in a call to “drawscreen” in
my main loop
then the screen clear works

( glinit proc does this :
glClearColor(0.0, 0.0, .25, 0.0);
)

if I use the thread, then my window remains black, however, if drawscreen is
explicitly
called in my main loop, the screen goes the dark blue as it should.
If I comment out the “SDL_GL_SwapBuffers( );” then the screen is not even
filled in with black,
but retains whatever the window was over last causing the too-well-known
"smudge" effect.

any ideas ?
thanks
Clive [ Entro-P ]

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: InterScan_Disclaimer.txt
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20011106/de124f2d/attachment.txt

Hi Clive,

When I move my display code into a thread, it’s broken.

void drawscreen() {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
SDL_GL_SwapBuffers( );
}

int DisplayThread(void *ignore) {
while (!quitapplication) {
SDL_mutexP(breach_mutex);
drawscreen();
SDL_mutexV(breach_mutex);
}
return 0;
}

If you want to draw from another thread than the thread which created the
OpenGL context, you?ll have to make this context the current GLX/WGL/AGL/…
rendering context of the calling thread.

any ideas ?

Don?t use a separate drawing thread.

or call SDL_SetVideoMode in the same thread than the drawing thread.
This could cause problems with other threads.

or make the SDL OpenGL context the current rendering context with:
Bool glXMakeCurrent(Display *dpy,
GLXDrawable drawable,
GLXContext ctx) respectively the WGL/AGL/… functions.
you?ll need some SDL internal data for doing this.

or wait for SDL 2.0 ;-)On Tuesday 06 November 2001 10:23, Clive Crous wrote:


Johannes Schmidt

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

Hi All,

When I move my display code into a thread, it’s broken.

That’s correct. You must display from the main thread.

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

Sam Lantinga wrote:

Hi All,

When I move my display code into a thread, it’s broken.

That’s correct. You must display from the main thread.

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

Will generating display lists work in a background thread? If I use a
background thread to generate my display lists (using GL_COMPILE, not
GL_COMPILE_AND_EXECUTE), and call them from the main thread, will that
work? I haven’t tried it yet in my program, but as the program is
getting bigger, I was considering it at some point in the future.

Thanks,
-Jeff

Display lists (and texture objects) are saved in an OpenGL context.
If you want to change data of an OpenGL context, you must assure that this
context is the current OpenGL context of the calling thread (See my
previous mail).

In short: It will not.

( At least not without digging into SDL sources and finding how you can get
the SDL video device and make the OpenGL context the current one.
But this would be a dirty hack. )On Wednesday 07 November 2001 01:54, user at domain.invalid wrote:

Sam Lantinga wrote:

Hi All,

When I move my display code into a thread, it’s broken.

That’s correct. You must display from the main thread.

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

Will generating display lists work in a background thread? If I use a
background thread to generate my display lists (using GL_COMPILE, not
GL_COMPILE_AND_EXECUTE), and call them from the main thread, will that
work? I haven’t tried it yet in my program, but as the program is
getting bigger, I was considering it at some point in the future.


Johannes Schmidt

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

Display lists can be shared between contexts. It’s a parameter to one of the
glX* functions.

  • Daniel Vogel, Programmer, Epic Games Inc.> -----Original Message-----

From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org]On Behalf Of
Johannes Schmidt
Sent: Wednesday, November 07, 2001 6:58 AM
To: sdl at libsdl.org
Subject: Re: [SDL] sdl && opengl - threading problems …

On Wednesday 07 November 2001 01:54, user at domain.invalid wrote:

Sam Lantinga wrote:

Hi All,

When I move my display code into a thread, it’s broken.

That’s correct. You must display from the main thread.

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

Will generating display lists work in a background thread? If I use a
background thread to generate my display lists (using GL_COMPILE, not
GL_COMPILE_AND_EXECUTE), and call them from the main thread, will that
work? I haven’t tried it yet in my program, but as the program is
getting bigger, I was considering it at some point in the future.

Display lists (and texture objects) are saved in an OpenGL context.
If you want to change data of an OpenGL context, you must assure
that this
context is the current OpenGL context of the calling thread (See my
previous mail).

In short: It will not.

( At least not without digging into SDL sources and finding how
you can get
the SDL video device and make the OpenGL context the current one.
But this would be a dirty hack. )


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

Display lists can be shared between contexts. It’s a parameter to one
of the
glX* functions.

yes, and there is also wglXXX such function on windows, but this is
system specific…

Of course, they can be shared. But how do you share them with SDL calls?
And as far as I know, you can create just one context with SDL.On Wednesday 07 November 2001 13:25, Daniel Vogel wrote:

Display lists can be shared between contexts. It’s a parameter to one of
the glX* functions.

  • Daniel Vogel, Programmer, Epic Games Inc.


Johannes Schmidt

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

i am not well remember the conclusion of the discussion…
will current (1.2) code be compatible with the future SDL1.3 library ?
i mean will the interface be the same ?

The system should deprecate functions, still supporting them, but in appropriate places suggest better usage.

That’s my five pennies> ----- Original Message -----

From: lloyd@galador.net (Lloyd Dupont)
To:
Sent: Wednesday, November 07, 2001 2:58 PM
Subject: [SDL] might be a stupid question (on SDL1.3) …

i am not well remember the conclusion of the discussion…
will current (1.2) code be compatible with the future SDL1.3 library ?
i mean will the interface be the same ?


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

The system should deprecate functions, still supporting them, but in appropriate places suggest better usage.

That’s my five pennies

but still good pennies ! thanks !