3

When trying to implement a simple OpenGL application, I was surprised that while it is easy to find plenty of examples and documentation on advanced rendering stuff, the Win32 framework is poorly documented and even most samples and tutorials do not implement this properly even for basic cases, not mentioning advanced stuff like multiple monitors. Despite of several hours of searching I was unable to find a way which would handle Alt-Tab reliably.

How should OpenGL fullscreen application respond to Alt-Tab? Which messages should the app react to (WM_ACTIVATE, WM_ACTIVATEAPP)? What should the reaction be? (Change the display resolution, destroy / create the rendering context, or destroy / create some OpenGL resources?)

Suma
  • 33,181
  • 16
  • 123
  • 191
  • possible duplicate of [Handling minimisation in Fullscreen Win32 OpenGL](http://stackoverflow.com/questions/2563596/handling-minimisation-in-fullscreen-win32-opengl) – Suma Apr 29 '11 at 12:38

1 Answers1

4

If the application uses some animation loop, suspend the loop, then just minimize the window. If it changed display resolution and gamma revert to the settings before changing them.

There's no need to destroy OpenGL context or resources; OpenGL uses an abstract resource model: If another program requires RAM of the GPU or other resources, your programs resources will be swapped out transparently.

EDIT:

Changing the window visibility status may require to reset the OpenGL viewport, so it's a good idea to either call glViewport apropriately in the display/rendering function, or at least set it in the resize handler, followed by a complete redraw.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • When I do this, after Alt-Tab my screen is black, and I know not why, or how to learn more about what is going wrong. It seems I am not alon - http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=170933&page=1 – Suma Apr 29 '11 at 13:01
  • @Suma: Just out of curiosity: Where do you set viewport and projection? I have a hunch, but don't want to tell it already ;) – datenwolf Apr 29 '11 at 13:07
  • I am not setting them, I leave them default. There are only two operations done in the context, glClear and glDrawPixels. – Suma Apr 29 '11 at 20:21
  • 3
    @Suma: Well, that's your problem then. Without properly setting the Viewport after a change in size or visiblity OpenGL is in a sort of limbo. You should always set glViewport first thing in your drawing function. Also you should set the projection, even if it's just identity; sooner or later you'll add multiple rendering passes in your program and this will keep you (your mind) sane. – datenwolf Apr 30 '11 at 09:09
  • Adding glViewport did help. If you will include this in the answer, I will accept it. – Suma May 26 '11 at 10:51