SDL_WM_ToggleFullScreen -- Toggles fullscreen mode


#include "SDL.h"

int SDL_WM_ToggleFullScreen(SDL_Surface *surface);


Toggles the application between windowed and fullscreen mode, if supported. (X11 is the only target currently supported, BeOS support is experimental).

For portability it's better to do something 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 */

Return Value

Returns 0 on failure or 1 on success.

See Also

SDL_SetVideoMode, SDL_Surface

SDL_WM_ToggleFullScreen (last edited 2010-01-10 19:33:18 by d-216-246-155-55)