16
votes

I am writing a game in C++ using SDL 1.2.14 and the OpenGL bindings included with it.

However, if the game is in fullscreen and I Alt - Tab out then back into the game, the results are unpredictable. The game logic still runs. However, rendering stops. I only see the last frame of the game that was drawn before the Alt-tab

I've made sure to re-initialize the OpenGL context and reload all textures when I get an SDL_APPACTIVE = 1 event and that seems to work for only one Alt - Tab, then all subsequent Alt - Tabs will stop rendering (I've made sure SDL_APPACTIVE is properly being handled each time and setting the context accordingly.)

I'd hazard a guess that SDL does something under the hood when minimizing the application that I'm not aware of.

Any ideas?

1
Good luck! This is one of those things that I've never satisfactorily figured out myself. I would really like to hear the answer.Mikola
What platform is this question about? For windows there's stackoverflow.com/questions/972299/… is for directX but may provide pointers.Guy Sirton
Are you sure it's SDL and not OpenGL which is causing problems? For instance, are you freeing up textures, buffers and other GL resources when you receive the initial event? Are you responding correctly to SDL_VIDEORESIZE events by calling SDL_SetVideoMode? And finally, have you tried the SDL forums? I'll bet someone's asked about the exact same problem there.John McFarlane

1 Answers

1
votes

It's a good pratice to "slow down" your fullscreen application when it looses the focus. Two reasons:

  1. User may need to Alt-Tab and do something important (like closing a heavy application that's hogging the resources). When he switches, the new application takes control, and the OS must release resources from your app as needed
  2. Modern OS uses a lot of GPU - this means it needs to release some graphics memory to work.

Try shutting down every GL resource you use when APPACTIVE=0 and alloc them again on APPACTIVE=1. If this solves, it was "your fault". If it does not solves, it's SDL (or GL or OS) bug.

EDIT: s/SO/OS/g