Using SDL from within an Windows MFC application

First, a little history. I’m working on Stella, the Atari 2600
emulator. As there’s no current maintainer for the Windows port, it
looks like I’m now the maintainer for the Linux and Windows ports.
For the Linux version, I’ve discontinued the X11 port and went with
pure SDL. I’m thinking of doing the same with the Windows port.

The Windows port has a frontend as well as a backend. The frontend is a
Windows MFC application which has a file lister, preference settings,
etc. The backend is currently written using DirectX, and is quite out
of date and difficult to work with (it hasn’t been updated in over 2
years). When a new game is to be emulated (ie, when the user
double-clicks a game in the file lister), a DirectX window is opened
and the emulation core takes over.

My question is, can I use SDL to do this backend part instead? I guess
my real question is that can the SDL subsystems be opened and closed
multiple times within the same program (when a new game is launched and
finished)? And if using SDL within a Windows application, does it have
to be initialized as soon as the actual Windows application starts? Or
can I do it whenever I want (which would sometimes be not at all)? If
this is possible, then I assume that the while SDL is active, it will
take over all event-handling. But when SDL exits, will event handling
return to the MFC application?

Any info on this is appreciated,
Steve

My question is, can I use SDL to do this backend part instead? I
guess my real question is that can the SDL subsystems be opened and
closed multiple times within the same program (when a new game is
launched and finished)? And if using SDL within a Windows
application, does it have to be initialized as soon as the actual
Windows application starts? Or can I do it whenever I want (which
would sometimes be not at all)? If this is possible, then I assume
that the while SDL is active, it will take over all event-handling.
But when SDL exits, will event handling return to the MFC
application?

One other thing I forgot to mention about this part. Of course
SDL_SetVideoMode() can be called multiple times per program invocation,
since I already do it in Linux when I resize the SDL screen.
Similarly, I assume that the sound subsystem can be opened and closed
multiple times.

So my more specific questions are:

  1. Can these subsystems be opened and closed multiple times per program
    invocation in SDL under Windows?

  2. Can SDL_Init() be called multiple times per program invocation in SDL
    under Windows? And what will happen once SDL_Quit() is called within
    an application? Does the whole application quit, or does the current
    SDL window close and processing can continue? If processing can
    continue, will the underlying Windows application still get events?

Thanks,
SteveOn Saturday 01 November 2003 12:04 pm, Stephen Anthony wrote:

So my more specific questions are:

  1. Can these subsystems be opened and closed multiple times per program
    invocation in SDL under Windows?

In my latest project, I call SDL_Init and SDL_Quit multiple times, even
just to open a window for defining keys, and the app does not quit entirely
when SDL_Quit is called, just that the window is closed. So yes (this is
under Windows btw) to that one.

  1. Can SDL_Init() be called multiple times per program invocation in SDL
    under Windows? And what will happen once SDL_Quit() is called within
    an application? Does the whole application quit, or does the current
    SDL window close and processing can continue? If processing can
    continue, will the underlying Windows application still get events?

See above. After I’d quit, I called “show” (Im using wxWindows so it might
not be the native call name) on my main menu-type window, and processing
continued under that, so I think yes to all of those as well.

HTH,

Neil.

Great, that’s what I wanted to hear :slight_smile: Right now, the launching is as
follows (in pseudocode):

MFC ::hide();
DirectX emulation ::run();
MFC ::show();

So that last show() is what you’re talking about. If this works, I can
have the emulator working in hours, vs. days (weeks?) if using DirectX
only.

Now my only problem is figuring out how to compile and link an SDL
application in Visual Studio .NET. Anyone have any info on this one?

Thanks,
SteveOn Saturday 01 November 2003 12:49 pm, Neil Brown wrote:

So my more specific questions are:

  1. Can these subsystems be opened and closed multiple times per
    program invocation in SDL under Windows?

In my latest project, I call SDL_Init and SDL_Quit multiple times,
even just to open a window for defining keys, and the app does not
quit entirely when SDL_Quit is called, just that the window is
closed. So yes (this is under Windows btw) to that one.

  1. Can SDL_Init() be called multiple times per program invocation in
    SDL under Windows? And what will happen once SDL_Quit() is called
    within an application? Does the whole application quit, or does
    the current SDL window close and processing can continue? If
    processing can continue, will the underlying Windows application
    still get events?

See above. After I’d quit, I called “show” (Im using wxWindows so it
might not be the native call name) on my main menu-type window, and
processing continued under that, so I think yes to all of those as
well.