Notes on using latest builds of SDL

Member
Posts: 233
Joined: 2003.05
Post: #1
I've seen people have trouble with building SDL, and I've recently worked with someone to fix a simple but horrible bug that inverted the y axis for mouse coordinates in OpenGL games. I'd thought I pass along some info.

Building SDL
If you go here:
http://www.libsdl.org/cvs.php
I recommend downloading the latest source snapshot version (the latest at the time of this post is Fri Nov 12) BUT you must have a recent version of StuffIt. Stuffit is notorious for breaking things (in my book anyway) and old versions will tell you the file is corrupt.

Now, decompress the pbprojects folder (there is now an Xcode folder) and look for the project file inside. When you open it up in Xcode you will come across a coreaudio bootstrap error of some kind. It's just a couple files that weren't added. Just drag them into the project, they are located here:
src/audio/macosx/SDL_coreaudio.h
src/audio/macosx/SDL_coreaudio.c
Drag them into the project and it should compile...
(anybody know if you still need to do this is 1.2.8 final? I haven't checked yet.)

The SDL_Main in these newer versions have updates that include standard menu items, but there are some alterations you could do to add command-key shortcut functionality, too. (Look in another post below or in the thread about SDL menus here at idevgames)

SDL 1.2.8 no longer has the following problem. I'll leave it here for those who are still using an old version:
Fixing the inverted mouse problem in 10.2
Now there is the inverted mouse thing. It turns out the fix is quite simple. Find this file:
src/video/quartz/SDL_QuartzWM.m

around line 150
change this line:
if(system_version >= 0x1030 $$ (SDL_VideoSurface->flags & SDL_OPENGL) ) {

to this:
if(SDL_VideoSurface->flags & SDL_OPENGL) {

It's just removing the system_version check. It should now work fine on 10.0 and up.

These fixes are being worked into the CVS version, so you may not have to change anything. Smile

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #2
Another note:
SDL is prepared properly for being installed inside an application package.
For mac users, it's advisable to distribute this way. Just add a copy build phase that copies the SDL.framework right inside the app. I keep the built framework in the same folder as my project so I can easily swap in and out the current version of SDL I want to use.

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #3
Adding primary command key shortcut functionality

The application menu has been added to the cvs code in SDL, but the shortcut keys are not enabled in SDLmain. Here's a solution that I've used successfully:

John Tanner on SDL newsgroup Wrote:I have been working on another approach to this
problem. My approach is for programs made using
Project Builder/XCode.

I add code to the SDLMain.m file of the project.

To get Cocoa to hear keystrokes (such as Cmd-Q, Cmd H
and the like), I add the statement
setenv ("SDL_ENABLEAPPEVENTS", "1", 1);
to the applicationDidFinishLoading: method in the
class SDLMain.

Next, I make sure Cocoa ignores keystrokes that do not
involve the command key, as Cocoa won't be able to
handle those; it'll "beep" at you. If your users don't
mind a "beep"ing computer while they play games, well,
you don't need to do this next step! :-P

In the implementation of SDLApplication, I add the
following method, which overrides the sendEvent:
method in NSApplication:
Code:
- (void)sendEvent:(NSEvent *)anEvent {
        if( NSKeyDown == [anEvent type] || NSKeyUp == [anEvent type] ) {
                if( [anEvent modifierFlags] & NSCommandKeyMask )
                        [super sendEvent: anEvent];
        } else
                [super sendEvent: anEvent];
}

This seems to work, but I have only tried it in one
application.

Thanks to the creators of the SDL Custom Cocoa
Application template. I would have never thought of
setting SDL_ENABLEAPPEVENTS without it.

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
MarkJ
Unregistered
 
Post: #4
aaron, do you know offhand if there is any support for properly minimizing SDL applications that use opengl in 1.2.8 without adding it yourself and recompiling SDL? I'd also like to add a menu item in the Window mode for a fullscreen toggle, and some sort of support for the zoom button to change the window size.

Would the best way to implement all this currently be to work it into my game's SDLMain.m myself? I have no Cocoa experience, but hopefully it shouldn't be that hard.

Edit: I've been messing with getting events in SDL, and attempting to use SDL_VIDEORESIZE, but when I call SDL_SetVideoMode() on my surface, everything is grey. Also the zoom button seems to halfway work. It will sort of zoom to a max size, with a bad offset, but when you try clicking it again, it won't set you back to the window's last size.

I'm starting to get a feeling that SDL is _really_ flaky when it comes to Mac OS X compatibility.
Quote this message in a reply
Member
Posts: 144
Joined: 2004.07
Post: #5
With the latest release of SDL (1.2.8) I believe the mouse inversion problem has been fixed. (FSAA works again for OSX too, yay!)
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #6
About the properly minimizing SDL, you've been to that thread, and afiak there is no way and no reason to put it anywhere else beside inside the SDL. Hopefully someone will add it in to the code so all SDL programmers can take advantage of it.

For adding menus you'll have to alter SDLMain. Simple as that.

SDL_SetVideoMode() is going to wipe your texture memory in openGL. You need to reload them... I'm just guessing you are using openGL.

As far as the maximize button, I haven't used resizable windows with SDL in a while so, I can't help out much there at the moment.

lightbringer:
Yes, that fix posted at the top of the thread is now implemented in SDL as of 1.2.8. All is right with that I hope. It was a horrible problem.

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
MarkJ
Unregistered
 
Post: #7
Ok, I've got window resizes working, and a fullscreen toggle into the menubar, but now I've noticed that if I enable multisampling for FSAA, SDL_SetVideoMode() always fails when its flagged to go fullscreen. Multisampling works fine in windowed mode, however. I'm using version 1.2.8 if that matters.

Code:
    SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, true );
    SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, 8 );
      
       gScreen = SDL_SetVideoMode (CGDisplayPixelsWide(kCGDirectMainDisplay), CGDisplayPixelsHigh(kCGDirectMainDisplay), 0, windowFlags);
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #8
Did you run into anything weird with the window resizing? Just asking because I might do this soon, and it's been awhile.

Unfortunately, I don't have a clue about the FSAA multisampling thing. Anyone get this to work full screen in SDL? I've never tried. I do know that there were some issues with FSAA before, maybe it needs more attention? Lightbringer, maybe you could shed some light on the subject? Grin Rolleyes

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
MarkJ
Unregistered
 
Post: #9
Nope. Resizing was pretty simple. Just set up your opengl state again, and rebind all your textures, and if you use display lists or anything, you'll have to rerender them.

Adding items and functionality to the menubar is pretty straightforward in SDLMain.m as well, and remember that SDL keeps event constants 24-32 open for programmers, so you can have menu items do a SDLPushEvent(kMyCustomMenuEvent); and deal with it in your SDL event processing code.

I am pissed about multisampling though. It works fine in windowed mode... Looks like time to consult the SDL mailing list.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #10
?? You should not have to reconstruct all your context state just because the drawable changed. Does SDL really kill the context when the window resizes?
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #11
arekkusu Wrote:?? You should not have to reconstruct all your context state just because the drawable changed. Does SDL really kill the context when the window resizes?
I don't know, but I'd just be thrilled if there were a way to switch to full screen w/o killing your context.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #12
Switching windowed/fullscreen, yes. Resizing the drawable-- no!
Quote this message in a reply
MarkJ
Unregistered
 
Post: #13
From what I've observed, every time you call SDL_SetVideoMode(), it makes a new GL context. It'd be nice if it didn't... This is another thing to hunt for information on.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #14
MarkJ Wrote:From what I've observed, every time you call SDL_SetVideoMode(), it makes a new GL context. It'd be nice if it didn't... This is another thing to hunt for information on.
There's a ToggleFullscreen function, but it doesn't appear to work.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cannot build release builds with Xcode/SDL :( yoki808 7 4,465 Nov 11, 2007 02:48 PM
Last Post: yoki808
  Using GL Extensions in latest Project Builder Bossa Nova 1 2,665 Feb 26, 2003 05:25 PM
Last Post: OneSadCookie