dodle
March 2nd, 2011, 09:02 AM
I figured out what I think to be a cross-platform way to toggle fullscreen in an SDL window and created a header file for it, but I am a novice programmer. Would someone mind checking my code for errors?
SDLToggleFS.h:
// Cross-platform Toggle FullScreen for an SDL Window
#ifndef _SDL_TOGGLE_FS
#define _SDL_TOGGLE_FS
#define SDL_WIN_SETTINGS surface->w, surface->h, surface->format->BitsPerPixel
// Check if SDL is already loaded
#ifndef _SDL_H
#include <SDL/SDL.h>
#endif
int IsFullScreen(SDL_Surface *surface)
{
if (surface->flags & SDL_FULLSCREEN) return 1; // return true if surface is fullscreen
return 0; // Return false if surface is windowed
}
int SDL_ToggleFS(SDL_Surface *surface)
{
Uint32 flags = surface->flags; // Get the video surface flags
if (IsFullScreen(surface))
{
// Swith to WINDOWED mode
if ((surface = SDL_SetVideoMode(SDL_WIN_SETTINGS, flags -= SDL_FULLSCREEN)) == NULL) return 0;
return 1;
}
// Swith to FULLSCREEN mode
if ((surface = SDL_SetVideoMode(SDL_WIN_SETTINGS, flags|SDL_FULLSCREEN)) == NULL) return 0;
return 1;
}
#endif
So far it works on both Ubuntu and Win32.
Note: This is for SDL 1.2, version 1.3 has a functions called SDL_SetWindowFullscreen.
SDLToggleFS.h:
// Cross-platform Toggle FullScreen for an SDL Window
#ifndef _SDL_TOGGLE_FS
#define _SDL_TOGGLE_FS
#define SDL_WIN_SETTINGS surface->w, surface->h, surface->format->BitsPerPixel
// Check if SDL is already loaded
#ifndef _SDL_H
#include <SDL/SDL.h>
#endif
int IsFullScreen(SDL_Surface *surface)
{
if (surface->flags & SDL_FULLSCREEN) return 1; // return true if surface is fullscreen
return 0; // Return false if surface is windowed
}
int SDL_ToggleFS(SDL_Surface *surface)
{
Uint32 flags = surface->flags; // Get the video surface flags
if (IsFullScreen(surface))
{
// Swith to WINDOWED mode
if ((surface = SDL_SetVideoMode(SDL_WIN_SETTINGS, flags -= SDL_FULLSCREEN)) == NULL) return 0;
return 1;
}
// Swith to FULLSCREEN mode
if ((surface = SDL_SetVideoMode(SDL_WIN_SETTINGS, flags|SDL_FULLSCREEN)) == NULL) return 0;
return 1;
}
#endif
So far it works on both Ubuntu and Win32.
Note: This is for SDL 1.2, version 1.3 has a functions called SDL_SetWindowFullscreen.