[SDL] Gtk2+SDL

Gonzalo Aguilar Delgado gad at aguilardelgado.com
Wed Dec 17 13:58:00 PST 2003


Thank you a lot Shawn!!!

Sorry for my late answer... I've messed up my mail...

Your explanation really clarifies my situation. It helped me a lot.
This is the kind of answers (full of refs and posible solutions) that
really helps.

I think I'll write a GTK2 widget when I get time. The In and Outs are
still hiden from my point of view. But I'll try to do my bests. Don't
know what I really need...

My program will be a full 3D-2D GPS Mapping suite built from gpsdrive
sources with SDL as backend (I tried with gtk alone and is really
slooooooow). But there are a lot of things I have to resolve first.

Thanks again. 
Gonzalo Aguilar

> On Thu Dec 11, 2003 at 03:08:58PM +0100, Gonzalo Aguilar Delgado wrote:
> > Anyone knows how to do SDL to work with GTK2?
> 
> Gonzalo, I will apologize up front for the length of my reply.  I've
> been pretty consumed with this issue lately.
> 
> Conceptually there seems to be 2 approaches to this: 1) GTK window devoted
> to hosting an SDL frame buffer surface where something is happening all
> the time.  The gtk-demo at libsdl.org is a good example of this approach.
> 2) SDL hosted as a widget within a larger GTK widget framework.  There are
> not too many good examples of this.  While I am sure that there are good
> reasons behind the first approach, I am not sure what they are exactly.
> If you want a window with a lot of drawing going on all the time, why not
> just use SDL without the overhead of GTK...?  But if you want to take
> advantage of GTK's widget set to build tools or an application that could
> also leverage SDL's media integration- well, it sounds like you are in the
> market for an SDL widget.
> 
> Anyway, so assuming that you want to take the widget approach, here are a
> couple of things to keep in mind:
> 
> The most popular options for getting SDL into a GTK widget are: using a
> widget like GtkDrawingArea as a container; building an SDL widget as
> either a derived or scratch built widget.  I believe that the container
> and derived widget approaches have problems with the expose event, and I
> prefer the scratch built approach.  For references see:
> 
> <http://www.gtk.org/tutorial/ch-writingyourownwidgets.html>
> 
> <http://sourceforge.net/projects/gtksdl/>
> 
> The SF gtksdl project is 100% unencumbered by documentation and has not
> been updated for some time.  However, it is useful as an example of a
> scratch built SDL widget and demonstrates the window hack.  It does not
> handle the expose event very well.
> 
> SDL Window hack: You can (and must) explicitly tell SDL which window to
> draw in by setting the SDL_WINDOWID environment variable.  See:
> <http://www.libsdl.org/pipermail/sdl/2000-August/029488.html>
> 
> Expose Event: See Sam's post here:
> <http://www.libsdl.org/pipermail/sdl/2003-January/051813.html> What you'll
> see happen is: your widget (or other SDL implementation code) will handle
> the expose event and flip the surface, update the rectangles, etc; and
> then GTK will apparently repaint the exposed area with the default widget
> color.  This happens because GTK tells GDK to clear the exposed area to
> the default widget color before the expose event is handled.  The problem
> is that SDL will finish its updates in the expose event handler before the
> GDK clear area finishes.  Unfortunately calling XSync did not work in my
> case.  A suggested solution: do not set GDK_EXPOSURE_MASK in the SDL
> widget window's attributes.event_mask member.  This means that your window
> will not receive expose events at all.  You will need to put your SDL
> widget in a container (a frame, for example) and wrap the frame's expose
> event with a function that calls your SDL widget's expose event.  It would
> be nice if you could tell GTK to ignore certain portions of your widget
> window, but not setting the GDK_EXPOSURE_MASK attribute is pretty much
> doing just that.  Owen Taylor talks about an anti-expose here:
> <http://www.gtk.org/~otaylor/gtk/2.0/gdk-drawing.html> See `Expose
> Queueing and Invalid regions'.  This could be a cool solution.
> 
> Finally, I am sorry to be long in explanation and short on code.  Its like
> a regular undergrad CS class around here!  All of the discussion that I
> could find on the GTK SDL issue seems to stop at ``Here's how you give SDL
> a window ID'' and ''I think you just put it in a GtkDrawingArea'' and ``My
> expose handler doesn't work''.  Hopefully my notes are helpful.  Please
> consider them (and me) open to correction.  My code is a mess, but if you
> want to look at it, I'll happily tar it up and send it to you.
> 
> Take care,
> shawn
> 
> _______________________________________________
> SDL mailing list
> SDL at libsdl.org
> http://www.libsdl.org/mailman/listinfo/sdl





More information about the SDL mailing list