FLTK and SDL two windows

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. :wink:

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.

AlvinOn 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

I’m using FLTK 1.1.x. I’m looping FLTK with FL::run().

I’m just starting to learn how to use FLTK. This is how I have it set up:

void make_window();
main(){
make_window();
SDL LOOP

return FL::run
}
void make_window(){
FLTK STUFF
}

I’m not sure what you mean by threads and threading ‘_’.

Thanks,
TaylorOn 2/3/07, Alvin wrote:

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. :wink:

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


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±--------------------+
|http://commabunny.com|
| |
|cout<<“Hello, noob!”;|
±--------------------+

The reason why nothing in the FLTK window works is that Fl::run() is being
called after the SDL LOOP code. Try this:

void make_window();
main()
{
make_window();

Fl::add_check(SDL UPDATE FUNCTION);

return FL::run;
}

void make_window()
{
FLTK STUFF
}

Here I use SDL UPDATE FUNCTION. What this would be is one iteration of your
SDL LOOP. Think of it as the code between the { and } of the while-loop
statement.

Doing it this way will have FLTK call the SDL UPDATE FUNCTION right before it
flushes the display and checks for events (keyboard, mouse, redrawing, etc.).
You can find the documentation for this and the rest of the FLTK API here:
http://www.fltk.org/doc-1.1/toc.html

Now, after saying all this, I cannot say if your game with be slow or
sluggish. It all depends on how long it takes the SDL UPDATE FUNCTION to
execute, including any other function that it calls. FLTK will not be able to
do anything else until your SDL UPDATE FUNCTION returns. This is why I
suggest putting the SDL UPDATE FUNCTION in its own thread. This way FLTK and
the SDL parts can happen independent of each other.

I believe this discussion is moving away from being SDL related and is
becoming off topic for this list. For more FLTK information and help, check
out the FLTK newsgroup:

Use the server: news.easysw.com in your news reader. Then subscribe to the
fltk.general newsgroup.

Or use can use the web interface here:

http://www.fltk.org/newsgroups.php

The newsgroup is very active and there are lots of people that would be
willing to help. I frequent it every day. :slight_smile:

AlvinOn Saturday 03 February 2007 16:52:32 Taylor “Assbone” Peterson wrote:

I’m using FLTK 1.1.x. I’m looping FLTK with FL::run().

I’m just starting to learn how to use FLTK. This is how I have it set up:

void make_window();
main(){
make_window();
SDL LOOP

return FL::run
}
void make_window(){
FLTK STUFF
}

I’m not sure what you mean by threads and threading ‘_’.

Thanks,
Taylor