[SDL] FLTK and SDL two windows

Alvin alvinbeach at gmail.com
Sat Feb 3 10:09:30 PST 2007


On Saturday 03 February 2007 12:52:51 Taylor "Assbone" Peterson wrote:
> Hey guys I'm having a problem with SDL and FLTK.
>
> I have it so that FLTK pops up a text box in its own window and SDL has its
> own window for the main game.  The problem is that in the SDL window (with
> the FLTK window open) the game lags behind.  And in the FLTK window ( with
> the SDL window open) nothing in the FLTK window works.  Anyone know the
> cause of this?
>
> Thanks,
> Taylor

What version of FLTK? 1.1.x or 2.0? What OS?

I'll assume FLTK 1.1.x because that's what I use. ;)

What are you doing to run the FLTK loop? Are you using Fl::run() or are you 
looping on Fl::wait()?

Are you performing the SDL operations (e.g. checking for SDL events, blitting, 
etc.) in the same thread/process as you are running the fltk loop?

I have done something similar to what you have described. What I did was in 
main() I do "return Fl::run()". Then in the main FLTK window (I'll call this 
the GUI) an SDL_Surface is created in the standard way a SDL surface is 
initially created. The SDL surface is usually a member of the GUI and is 
created in the GUI's ctor. After the SDL surface is created, a thread is 
created using the SDL surface as it's parameter. This thread is responsible 
for all the SDL operations. The GUI and SDL thread communicate via a mutex 
and/or FLTK's threading support (e.g. Fl::lock(), Fl::awake(), Fl::unlock()). 
The synchronisation method depends on which way the communication will 
travel.

For the thread, I use pthreads but it probably makes more sense to use SDL's 
Threading support.

If you don't want to use another thread, take a look at Fl::add_check(). That 
could work? The function you pass to Fl::add_check() would be responsible for 
all the SDL operations. The fltk loop will then call this function 
automagically for you while it is looking for its own events and redrawing, 
etc. I don't know if this would be slow though. I guess it depends on the SDL 
operations you are doing.

Alvin




More information about the SDL mailing list