Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SDL OpenGL Alt-tab in fullscreen has unpredictable results

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?

like image 606
snobaste Avatar asked Jun 25 '11 06:06

snobaste


1 Answers

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

like image 136
Eduardo Costa Avatar answered Oct 17 '22 23:10

Eduardo Costa