SDL OpenGL Alt-tab in fullscreen has unpredictable results
Asked Answered
M

1

16

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?

Martinson answered 25/6, 2011 at 6:23 Comment(3)
Good luck! This is one of those things that I've never satisfactorily figured out myself. I would really like to hear the answer.Pardo
What platform is this question about? For windows there's #972799 is for directX but may provide pointers.Trailer
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.Desmonddesmoulins
A
1

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

Arbil answered 13/7, 2011 at 13:46 Comment(3)
What do you intend "SO" to stand for?Winker
My apologies. That was supposed to be OS, as in "Operating System". "SO" is the acronym in my native language.Arbil
Ah! Learn something new every day. Thank you.Winker

© 2022 - 2024 — McMap. All rights reserved.