SDL fullscreen toggle turns blank

Started by
6 comments, last by FlyingSolo 14 years, 1 month ago
I have problems with toggeling to fullscreen. I've read that SDL_WM_ToggleFullScreen doesn't work on Windows, so I made that into a special case. I have no problems entering fullscreen in my init of the window by using the code: flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_RESIZABLE | SDL_HWSURFACE; int tmpFlags = flags; if(fs) { tmpFlags ^= SDL_FULLSCREEN; } // Create the window screen = SDL_SetVideoMode(w, h, wbpp, tmpFlags); If fs is set it enters fullscreen and renders properly. However, when I toggle the fullscreen with: if(!SDL_WM_ToggleFullScreen(screen)) { // SDL_WM_ToggleFullScreen not supported. Set SDL_SetVideoMode again. int tmpFlags = flags | SDL_FULLSCREEN; if(fullscreen) { tmpFlags ^= SDL_FULLSCREEN; } // Create the window screen = SDL_SetVideoMode(width, height, bpp, tmpFlags); } it goes into fullscreen mode but it's just blank. (screen, flags, width, height and bpp are private variables in my class). Any ideas what I'm doing wrong?
Advertisement

Well if you're doing rendering with textures you have to reload them after the fullscreen toggle because any indices you may have retreived from opengl before the toggle will no longer reference valid textures.
I'm not using any textures at the moment.
The first thing I noticed when looking at your code is that the video flags appear to be incorrect. SDL_GL_DOUBLEBUFFER is intended to be used with the 'set attribute' function, not as a video flag. Also, I don't think SDL_HWSURFACE is necessary when creating an OpenGL rendering context.

I don't know if this is what's causing the problem you describe, but you might start by fixing the video flags, and see if that makes any difference.
Replace tmpFlags ^= SDL_FULLSCREEN; with tmpflags |= SDL_FULLSCREEN;
Quote:http://sdl.beuc.net/sdl.wiki/SDL_SetVideoMode
User note 2: Also note that, in Windows, setting the video mode resets the current OpenGL context. You must execute again the OpenGL initialization code (set the clear color or the shade model, or reload textures, for example) after calling SDL_SetVideoMode. In Linux, however, it works fine, and the initialization code only needs to be executed after the first call to SDL_SetVideoMode (although there is no harm in executing the initialization code after each call to SDL_SetVideoMode, for example for a multiplatform application).

Also...
Quote:Original post by jyk
The first thing I noticed when looking at your code is that the video flags appear to be incorrect. SDL_GL_DOUBLEBUFFER is intended to be used with the 'set attribute' function, not as a video flag. Also, I don't think SDL_HWSURFACE is necessary when creating an OpenGL rendering context.

I don't know if this is what's causing the problem you describe, but you might start by fixing the video flags, and see if that makes any difference.

This same mistake was recently made by somebody else here. Is there some tutorial that does this?
This space for rent.
Thanks for poiting out my errors. I think that I have to do the OpenGL initialization again. That's probably why I get a blank screen. But you'd think that the next buffer swap would fix that for you. :)
Quote:Original post by GlassBil
Thanks for poiting out my errors. I think that I have to do the OpenGL initialization again. That's probably why I get a blank screen. But you'd think that the next buffer swap would fix that for you. :)


I found that I had to re-do the gl init, but my textures were intact.

SDL is getting slammed for this but once you know about it - it's not a problem to cope with it.

Just my 2c.

This topic is closed to new replies.

Advertisement