Using SDL with gui library

How can I use SDL2 with some gui libraries , like Qt or GTK 2 or 3? I suppose I would need to use SDL_CreateWindowFrom, however as read it’s used to making SDL_Window from native (in my case X11) Windows. I would like to create gui for emulator i have wriiten with SDL2, for example to render SDL’s image to Qt’s GraphicView.

I have read somewhere about hack working by putting environment variable with window id. How can this be used?

Message-ID: <1379093178.m2f.39259 at forums.libsdl.org>
Content-Type: text/plain; charset=“iso-8859-1”

How can I use SDL2 with some gui libraries , like Qt or GTK 2 or 3? I
suppose I would need to use SDL_CreateWindowFrom, however as read it’s used
to making SDL_Window from native (in my case X11) Windows. I would like to
create gui for emulator i have wriiten with SDL2, for example to render
SDL’s image to Qt’s GraphicView.

I’m sorry, but what EXACTLY are you trying to do? Are you trying to
use SDL2 to provide the gui controls, or are you trying to use e.g. QT
to render the gui controls? If you’re wanting to use QT’s widgets to
render some buttons & such, then I believe the correct choice is to
create a specific QT widget, and give the window used by that widget
to the SDL_CreateWindowFrom function. If you want to do something
other than use QT’s widgets, then you’ll need to tell us what that is.> Date: Fri, 13 Sep 2013 17:26:18 +0000

From: “bartexsz”
To: sdl at lists.libsdl.org
Subject: [SDL] Using SDL with gui library

Exactly, I was trying to use qt to render controls and sdl to render graphic from emulator i wrote.

How will SDL2 behave in case you have written about? Will it use whole window or only for example Graphic View widget?

Hi there,

A fairly similar question with the thread “Using SDL with gui library”

Is there someone who knows an open-source program that’s already
successfully integrates SDL2 (in OpenGL “mode”) with GTK 3 for majors
desktop PC OS’es ?
Is there some general ideas or some snippets of code to follow ?

Thanks,
Ludovic

Ludovic POUZENC wrote:

Hi there,

A fairly similar question with the thread “Using SDL with gui library”

Is there someone who knows an open-source program that’s already
successfully integrates SDL2 (in OpenGL “mode”) with GTK 3 for majors
desktop PC OS’es ?
Is there some general ideas or some snippets of code to follow ?

Thanks,
Ludovic


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

Yeah, It would be helpfull to find one, however i foound only spectrum3d, which uses sdl1.2 …

And a quite complicated maneer (for Spectrum3D). I have a dead project
about a simple GUI for teaching OpenCL things. Need vextex array buffers
and some Open GL 3.2+ context.
I didn’t find a reliable and maintanable solution last year for mixing
GTK, opengl and openCL.

Regards,
LudovicOn 15/09/2013 19:14, bartexsz wrote:

Ludovic POUZENC wrote:
Hi there,

A fairly similar question with the thread “Using SDL with gui library”

Is there someone who knows an open-source program that’s already
successfully integrates SDL2 (in OpenGL “mode”) with GTK 3 for majors
desktop PC OS’es ?
Is there some general ideas or some snippets of code to follow ?

Thanks,
Ludovic


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Yeah, It would be helpfull to find one, however i foound only
spectrum3d, which uses sdl1.2 …


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

2013/9/15 Ludovic Pouzenc

And a quite complicated maneer (for Spectrum3D). I have a dead project
about a simple GUI for teaching OpenCL things. Need vextex array buffers
and some Open GL 3.2+ context.
I didn’t find a reliable and maintanable solution last year for mixing
GTK, opengl and openCL.

What was your experience with gtkglext [1] like?

[1] https://projects.gnome.org/gtkglext/

Jonas

Hi there,

Lead dev of the SDL version of FCEUX Nintendo NES/Famicom emulator here. FCEUX utilizes SDL 1.2 for the bulk of the emulator(currently - working on migrating to SDL 2.0 when I get the free time) and optionally uses GTK for option dialogs and the menubar (works with both 2 and 3 as a compile time option). Here’s what it looks like in action:

http://xannode.com/blog/wp-content/uploads/2011/05/screenie.png

The implementation of this was not really that straightfoward and currently only works as expected when running on Linux and X11. This is done by creating a blank GTK widget (event box IIRC) and grabbing the XWINDOWID of that widget and forcing SDL to use this widget to draw on by setting the “SDL_XWINDOWID” environment variable to that value. I can’t really find any solid documentation of this, but you’re welcome to view the FCEUX source to see how this is handled here if you’d like (or if you dare):

http://sourceforge.net/p/fceultra/code/HEAD/tree/fceu/trunk/src/drivers/sdl/gui.cpp - check out the code around InitGtkSubsystem

However, I would not recommend doing this for a variety of reasons:

  1. For whatever reason, this method of embedding the SDL window inside a GTK window does not work on OS X w/ X11 emulation. Fat chance that this would work in Windows either.
  2. This will not work if the application is compiled for Wayland/Weston or anything other than X11

In my particular situation using this solution contributed to a really messy codebase built around a non-portable hack. I would also be interested in a clean way of either A) using both SDL and GTK/QT/SomeOtherToolKit or B) using SDL to draw menubars that match the look and feel of the host operating system.

For what it’s worth, the Gens sega emulator utilizes both GTK2 and SDL (1.2) to do something similar and I do not believe that gens utilizes the XWINDOWID hack but I could be wrong. I have not had the time to inspect the source code: http://gens.me/

Likewise, the Snes9x-GTK emulator project utilizes both GTK2 and SDL (1.2) in a similar fashion: https://code.google.com/p/snes9x-gtk/ I have not had an opportunity to inspect the code to see how this is implemented.

I just wanted to share my personal experience on this issue and I’d love to hear anyone else’s

edit: I mentioned that this only works as expected on Linux and X11. This method also seems to work fine on some of the BSD variants that I have tried. I had really meant that it does not work as expected on OSX or at all on MS Windows.

Just wanted to clarify - sorry for any potential confusion

Hi,

I have been wondering if it wouldn’t be easier to just straight up ditch
SDL and go full GTK/Qt;
for GTK there isgtkglext that let’s you use OpenGL to draw into a widget,
and I’m sure Qt has
good OpenGL integration as well. What do you still need SDL for? If it’s
just GL context creation,
it might not be worth going through the trouble of toolkit integration.

Jonas

For what its worth, the hack used to mix SDL1.2 and Qt4 was similar in
nature to the GTK one mentioned. Its just not a good solution. Furthermore
the Qt devs explained that many of the OpenGL functionality in Qt4 were
flawed around the time Qt5 came out. I use Qt alot and would definitely
like to see a proper solution using SDL2 and Qt5. SDL’s strength has always
been porting, and its weakness is the lack of decent GUI integration so I’m
not sure why this topic isn’t at least being looked into for future
versions now that SDL2 is out. Being able to mix the graphics between the
two easily would really be nice. Joystick/Gamepad/Haptic is really the only
thing I use SDL for that Qt doesn’t reasonably provide. Qt’s QGraphicsView
is nice, but being able to use SDL graphics with Qt in a non-hackish way
will really eliminate the GUI issue once and for all.

  • Swyped from my droid.On Sep 19, 2013 12:30 AM, “Jonas Kulla” wrote:

Hi,

I have been wondering if it wouldn’t be easier to just straight up ditch
SDL and go full GTK/Qt;
for GTK there isgtkglext that let’s you use OpenGL to draw into a widget,
and I’m sure Qt has
good OpenGL integration as well. What do you still need SDL for? If it’s
just GL context creation,
it might not be worth going through the trouble of toolkit integration.

Jonas


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

It looks like what you’re looking for is called
librockethttp://librocket.com/wiki/documentation.
Using (almost) HTML to build UI is quite simple and there are several
context implementations for SDL2/OpenGLOn Thu, Sep 19, 2013 at 4:40 PM, Jonathan Greig wrote:

For what its worth, the hack used to mix SDL1.2 and Qt4 was similar in
nature to the GTK one mentioned. Its just not a good solution. Furthermore
the Qt devs explained that many of the OpenGL functionality in Qt4 were
flawed around the time Qt5 came out. I use Qt alot and would definitely
like to see a proper solution using SDL2 and Qt5. SDL’s strength has always
been porting, and its weakness is the lack of decent GUI integration so I’m
not sure why this topic isn’t at least being looked into for future
versions now that SDL2 is out. Being able to mix the graphics between the
two easily would really be nice. Joystick/Gamepad/Haptic is really the only
thing I use SDL for that Qt doesn’t reasonably provide. Qt’s QGraphicsView
is nice, but being able to use SDL graphics with Qt in a non-hackish way
will really eliminate the GUI issue once and for all.

  • Swyped from my droid.

On Sep 19, 2013 12:30 AM, “Jonas Kulla” wrote:

Hi,

I have been wondering if it wouldn’t be easier to just straight up ditch
SDL and go full GTK/Qt;
for GTK there isgtkglext that let’s you use OpenGL to draw into a widget,
and I’m sure Qt has
good OpenGL integration as well. What do you still need SDL for? If it’s
just GL context creation,
it might not be worth going through the trouble of toolkit integration.

Jonas


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


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


Regards,
Stanislav Yudin

punkrockguy318: Great to see another emu person having this problem ;). I’m the current maintainer of Nestopia.

So what we’re trying to accomplish is similar. I’ve completed the port to SDL 2.0 already, but still can’t embed in the window. I’m using GTK+3, but that shouldn’t make a difference. The SDL_WINDOWID hack no longer works with SDL 2.0, at least as far as I can tell. I was using that method with SDL 1.2 previously and it worked great.

Gens uses the same method as FCEUX. Actually I think it might be the same code… the GDK to SDL key function is the same at least (and I also grabbed it… the wonders of the GPL!).

As for GtkGLExt, it’s a dead technology now. I contacted the guy who ported it to GTK+3, and he no longer has interest in maintaining it, since it was rejected upstream. So that’s a GTK+2-only solution, and if you’re worried about supporting Wayland eventually, you need GTK+3.

The ideal solution would be to get SDL_CreateWindowFrom working for this. But it doesn’t seem like that works either… maybe that function simply was not meant for this purpose.

This thread is another good reference, it’s about the same issue really: http://forums.libsdl.org/viewtopic.php?t=9247