SDL with wxWidgets?

Hello!

Me and some friends are writing a game in SDL. The game is up and running
and now we need a tool. I’m going to write the tool with wxWidgets, but how
could I run our SDL game inside a subwindow? It would be great to realtime
test maps etc. The game: window and input uses SDL, graphics uses OpenGL and
audio uses OpenAL.

Does anyone know how to set up SDL to work in a already created window (from
wxWidgets) ?

Thank you
//John-Philip

Hello,

Me and some friends are writing a game in SDL. The game is up and running
and now we need a tool. I’m going to write the tool with wxWidgets, but how
could I run our SDL game inside a subwindow? It would be great to realtime
test maps etc. The game: window and input uses SDL, graphics uses OpenGL and
audio uses OpenAL.

Does anyone know how to set up SDL to work in a already created window (from
wxWidgets) ?

I think I remember something combining wxWindows and SDL, I think it
was in Python (pyGame and wxPython), but I can’t find it anymore. It
didn’t strike me as very common, though.

You didn’t mention it, but I assume you already thought of stripping SDL
altogether from the tool? wxWidgets has a wxGLCanvas class, which
provides you with an OpenGL context (which is all you need for OpenGL).
It should also provide keyboard input and mouse input (even without
buttons pressed, I believe). wxWidgets even seems to have joystick
support, but I’m sure you can still use the SDL version (if you use
joysticks).

In fact, you should be able to use SDL (including video) without changes
except for the fact that you can’t

  • create a main window
  • draw directly to the main window
  • receive events (keyboard, mouse) from the main window.
    But since you are using OpenGL anyway, drawing shouldn’t be a problem.
    As for the events, maybe you can call SDL_PushEvent from the wxWidget
    event callbacks?

In my opinion, this should be a lot easier to implement and a lot more
portable than trying to get wxWidgets to accept the (top-level !) SDL
window, or getting SDL to work on a wxWindow…

Unless, of course, someone else answers your question with a wxSDLCanvas :wink:

By, and good luck,

Ben

John-Philip Johansson wrote:

Does anyone know how to set up SDL to work in a already created window (from
wxWidgets) ?

This has been discussed before. Below is what I have in my archive…–
Milan Babuskov
http://njam.sourceforge.net

----- Original Message -----
Subject: Re: [SDL] wxWindows, QT and SDL
Date: Thu, 29 Jan 2004 11:11:03 -0600
From: xodsdl@starmen.net (xodnizel)
Reply-To: sdl at libsdl.org
To: sdl at libsdl.org
References: <KNEHLBMHNKOKIFLAOMAFKEMBCFAA.bruce at opengl.com.br>

I’ve used wxWindows with SDL.

I’ve only used it in separate windows, though(one SDL window and a GUI
control window). I think wxWindows supports OpenGL natively(you can
render directly in a wxWindows window), but I can’t remember the details
offhand.

I used wxWindows entry point instead of SDL’s under Win32, as it was the
simplest way to go. You will need to reimplement some of SDL’s Win32
WinMain, otherwise your application may experience odd behavior/crashing.

If you want to have your own event loop(which you most certainly will
want to have), you can declare your own MainLoop() in your class derived
from wxApp.
Under GTK+, it should be sufficient to call wxYield() and
wxLog::FlushActive() regularly, but that doesn’t work so well on Win32.
On Win32, I use code similar to the following in my event loop:

     #if wxUSE_THREADS
     wxMutexGuiLeaveOrEnter();
     #endif // wxUSE_THREADS

     while(Pending()) DoMessage();

     while(ProcessIdle())
     {
      DoMessage();
     }

I’ve only tested it with wxWindows 2.4.2. wxWindows 2.6(or maybe it was
3.0?) is supposed to have an event loop class, which may help solve the
issue of having your own event loop without resorting to hackish solutions.