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.