Reputation: 7205
I have an issue when toggling an SDL application in fullscreen to windowed and back:
SDL_SetVideoMode( (int)screenSize.x, (int)screenSize.y, 32, SDL_NOFRAME | SDL_FULLSCREEN | SDL_OPENGL );
// now upload all active textures back into the GPU
// toggle from fullscreen to windowed
SDL_SetVideoMode( (int)screenSize.x, (int)screenSize.y, 32, SDL_OPENGL );
The issue here is that the "SDL_NOFRAME" flag doesnt seem to work - I actually see a frame in the fullscreen app!
Note: by "Frame" I mean the windows window-frame with the name of the app on the title bar, and the minimize, restore and close buttons.
Everything works fine if I start the app directly in full-screen or windowed mode, its just that the toggling doesn't work. If I use SDL_NOFRAME for both windowed AND fullscreen mode, it works as expected, but this is not what I want.
edit: The documentation for this function can be read off here: http://www.libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode
Going from Fullscreen -> Windowed -> Fullscreen, the error is as above. From Windowed->Fullscreen, The result is slightly different, I see a black bar instead of the frame...
Upvotes: 0
Views: 3763
Reputation: 7363
Which version of SDL are you using? I assumed it was SDL-1.2.14 and tried the following with that version:
#include "SDL.h"
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen;
#if 1
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
SDL_Delay(2000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_FULLSCREEN);
SDL_Delay(5000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
SDL_Delay(5000);
#else
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_FULLSCREEN);
SDL_Delay(2000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
SDL_Delay(5000);
screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL | SDL_FULLSCREEN);
SDL_Delay(5000);
#endif
SDL_Quit();
return 0;
}
The code goes from windowd to fullscreen and back or the opposite way around depending on the preprocessor flag set.
I do not get a window frame in fullscreen mode while there is one when omit SDL_FULLSCREEN
. I also assign the return value of SDL_SetVideoMode
to a variable as this might change. When toggling to fullscreen windows might still show the contents of the screen that happend to be displayed while you were in windowed mode. In fullscreen mode that resulted in me seeing the SDL_app window which was located at the top left of the screen. You would have to clear the screen to make sure only your own stuff is beeing displayed.
There is also an SDL_WM_ToggleFullscreen
function. It does not work on Windows but the link to the documentation contains an example on how to handle toggling windowed/fullscreen in a portable way.
The code example from the SDL documentation looks like this:
/* Anyone may copy and alter this fragment of pseudo-code and use it however they wish */
#include "SDL.h" /* The only library needed to do this */
Uint32 flags = SDL_SWSURFACE; /* Start with whatever flags you prefer */
SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, flags); /* Start with whatever settings you prefer */
/* -- Portable Fullscreen Toggling --
As of SDL 1.2.10, if width and height are both 0, SDL_SetVideoMode will use the
width and height of the current video mode (or the desktop mode, if no mode has been set).
Use 0 for Height, Width, and Color Depth to keep the current values. */
flags = screen->flags; /* Save the current flags in case toggling fails */
screen = SDL_SetVideoMode(0, 0, 0, screen->flags ^ SDL_FULLSCREEN); /*Toggles FullScreen Mode */
if(screen == NULL) screen = SDL_SetVideoMode(0, 0, 0, flags); /* If toggle FullScreen failed, then switch back */
if(screen == NULL) exit(1); /* If you can't switch back for some reason, then epic fail */
The example does not mention what happens when the SDL_OPENGL
flag is used while toggling window mode. I fear the OpenGL context might get destroyed and recreated which would mean that you'd have to reinitialize OpenGL and reload all textures and geometry when toggling
window mode.
edit:
I was able to confirm, that the OpenGL context gets destroyed after toggling the display mode:
Creating a display list
GLuint list = glGenLists(1);
glNewList(list, GL_COMPILE);
glBegin(GL_LINES);
glVertex2f(0.0f, 0.0f);
glVertex2f(1.0f, 1.0f);
glEnd();
glEndList();
and calling it with
glClear(GL_COLOR_BUFFER_BIT);
glCallList(list);
worked. After a SDL_SetVideoMode
calling the same list resulted in nothing to be drawn.
Upvotes: 1