OS X: SDL as subclass of NSView?

Is it possible to have SDL draw into a custom NSView? Would it be
possible somehow to send messages between my game code and other
Cocoa/Obj-C stuff like buttons? It would be nice if I could have a
conventional aqua interface, but use SDL for the actual game code.

Or am I barking up the wrong tree here? I’m a bit of a newbie, so be
kind :wink:

Thanks!
–Joseph Humfrey

Joseph Humfrey wrote:

Is it possible to have SDL draw into a custom NSView? Would it be
possible somehow to send messages between my game code and other
Cocoa/Obj-C stuff like buttons? It would be nice if I could have a
conventional aqua interface, but use SDL for the actual game code.

Or am I barking up the wrong tree here? I’m a bit of a newbie, so be
kind :wink:

Thanks!
–Joseph Humfrey

I don’t have Cocoa experience but what about trying the Unix/Windows
soluction for that problem?

If you create the SDL_WINDOWID environment variable with the window
handle, before initializing SDL, it will use that window.

For example,

char buffer [1024];
sprintf (buffer, 1024, “SDL_WINDOWID=%ld”, your window handle);
putenv (buffer);

SDL_Init (the usual stuff)

…–
Paulo Pinto

Anything is possible - we could do all kinds of crazy things with SDL
and Cocoa integration. But SDL doesn’t have this support yet. It
wouldn’t be too difficult to have a SDL_NSVIEWID= hack similar to what
other folks are doing.

Another small hack may have to be put in place to because SDL takes
over the Cocoa event loop (SDL gets all events sent to the
application - not just the view you are drawing into). This is a
necessary evil if you want your buttons to throb and other such things.

If people are interested, I could put together the necessary pieces and
a demo application. Let me know.

Oh, I just remembered - you could use JSDL (Java wrapper for SDL)
with the Cocoa-Java API’s (or Swing, or whatever) already without these
hacks at all. This would probably be much nicer and more flexible -
albeit somewhat slower.

Cheers,
DarrellOn Wednesday, July 16, 2003, at 03:01 PM, sdl-request at libsdl.org wrote:

Is it possible to have SDL draw into a custom NSView? Would it be
possible somehow to send messages between my game code and other
Cocoa/Obj-C stuff like buttons? It would be nice if I could have a
conventional aqua interface, but use SDL for the actual game code.

Hi all,

Is it possible to have SDL draw into a custom NSView?
[snip]
It wouldn’t be too difficult to have a SDL_NSVIEWID= hack similar
to what other folks are doing.
[snip]
I could put together the necessary pieces and
a demo application. Let me know.
Funny this should come up within a day of me encountering the same issue…

My situation:

I’m trying to get wxWindows to embed a pygame (Python libsdl bindings)
window to play MPEG video with libsmpeg on Mac OS X 10.2… (Yeah, I
know, I like the easy life… :slight_smile: )

I got the video playing, but couldn’t get the video frame embedded.

Anyway, I discovered the “window id hack” and got it working on a
Windows machine but not on my OS X machine. I then discovered that the
reason for that is that the Mac OS X libsdl doesn’t implement it.

I took a look at the code and was thinking “hmmm, this isn’t a one line
fix”, so personally, I’d be really thankful if Darrell could “put
together the necessary pieces”. :slight_smile:

As it turns out there’s an issue on the OS X wxPython side of things too
because it doesn’t implement the required ‘GetHandle’ method. I’ve found
some code that apparently adds this at the wxWindows level, but haven’t
tried it yet. (I was figuring I’d find out what libsdl needed, only to
discover that it didn’t include the window id hack.)

I probably can’t be much help other than as a tester, but if someone has
the skills + knowledge to implement it I’d be grateful.

Oh, I thought I’d make a comment about libsmpeg while I’m here. I’ve
gotten it to work on OS X 10.2 as far as basic playback is concerned but
only if the video is being playeback at (0,0) offset. If you try and
offset it within the frame it doesn’t display the video, although it
plays the audio. I thought it might have been a wxPython issue, but I
tried calling the SMPEG_MoveDisplay (I think) routine within the
plaympeg demo and it doesn’t work there either, so it looks like it’s an
issue with libsmpeg.

I remember seeing a comment about the co-ordinate directions from the
point of origin of the Mac OS X graphics being different, so was
wondering if that might be an issue.

Anyway, just providing a data point on that issue.

Hope this encouragement or notes are helpful for someone… :slight_smile:

–Phil.

P.S. On a related note, I’m looking at trying to get things running
under the Aqua X11 environment in the interim, anyone had experience
with that?