[SDL] Screensaver issues on Mac OS using SDL >1.2.12

Oliver Bock oliver.bock at aei.mpg.de
Tue Sep 16 06:39:27 PDT 2008


Hi Ryan,

Thanks for your elaborate feedback!

Ryan C. Gordon wrote:
> I think that, ultimately, there was only a very small portion of SDL 
> that needed to be used in the screen saver. The game used all sorts of 
> things, but I suspect that the screen saver really only used 
> SDL_GetTicks(). I never call SDL_SetVideoMode() for the screensaver. You 
> might be better off #ifdef'ing the SDL code if it's just a few small 
> things, like timers; on deadline, I figured I'd risk leaving the SDL 
> calls in, rather than try to weed them all out.

 > You can use OpenGL, but you shouldn't use any SDL calls that depend on
 > the existance of a valid GL context. You might be able to use the SDL
 > window id hack, but I'd avoid it. All of your effort is going to be in
 > standard GL calls anyhow, and the GL context is prepared simply enough
 > here, so there isn't really any SDL video things you _need_.

Sorry, I forgot to point out that my application uses SDL to provide an 
OpenGL context and to do event handling as well as window management. 
All the rest is done in pure OpenGL. Please keep in mind that my SDL 
application is just a "normal" windowed app that can be switched to 
fullscreen mode. The screensaver itself is a 3rd party app that in turn 
launches my SDL application. As far as SDL goes I use these methods:

Initialization:
- SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)
- SDL_VideoModeOK()
- SDL_GL_SetAttribute()
- SDL_WM_SetCaption(); used before going to fullscreen (if requested)
- SDL_ShowCursor(); cursor hidden in fullscreen mode
- SDL_SetVideoMode(); windowed mode, or fullscreen as "screensaver"

Event handling:
- SDL_EventState()
- SDL_AddTimer(); two user events (render event, data update event)
- SDL_PushEvent(); pushing user events
- SDL_WaitEvent()

Rendering:
- SDL_GL_SwapBuffers()

On exit:
- SDL_FreeSurface()
- SDL_Quit()

> - You can't link to SDL directly. I had it shipped with the game 
> (@executable_path/libSDL.dylib), but "@executable_path" is meaningless 
> for screensavers, since your saver is loaded into someone else's process 
> with a different path. I ended up using dlopen() on the SDL library at 
> startup and picking out the symbols I needed, and then calling SDL_Init().

My application is (has to be) linked statically.

> - Your mainline doesn't run. You have to supply an (Objective-C!) 
> subclass of ScreenSaverView, which will be a little glue between the Mac 
> interfaces and your own screensaver, which will be mostly unchanged. 
> System Preferences will load your bundle and run the saver in a little 
> preview window, and a different process will load it fullscreen as the 
> actual screensaver later. This subclass also dictates whether System 
> Preferences provides a configuration dialog for the saver, when it 
> should redraw, etc.
 >
 > - link the saver with "-framework ScreenSaver -bundle" ... I think you
 > give it an Info.plist and put it all in "~/Library/Screen Savers" but
 > I don't have those details in front of me.

As far as I understand both of this applies to the "glue" only, which is 
in my case provided by the 3rd party app which just launches the actual 
SDL application.

> - You don't swap buffers, you just call glFlush() ...(apparently.)

I do SDL_GL_SwapBuffers() after glFlush() in every render step.


Here's one thing I noticed in the meantime: when I run my application in 
windowed mode (standalone), it *doesn't* prevent a given screensaver 
like "Flurry" from being launched. This indicates that there're no 
events generated by SDL that could cause the problem I experience. 
However, when I run it in fullscreen mode (still standalone), "Flurry" 
doesn't start. I verified that by watching for its task via ssh as it 
could have been launched on a lower z-layer than my running app - it 
wasn't.

Do you have any idea what the difference is between windowed and 
fullscreen mode? Does SDL behave differently in that case (generating 
events?) or is this something that Mac OS notices somehow and prevents 
subsequent screensaver launches...? The same code works just fine on 
Windows when cross-compiled with MinGW.


Thanks,

Oliver




More information about the SDL mailing list