Since SDL_WM_ToggleFullScreen only works in X11 I created a custom header file for toggling fullscreen on an SDL window. But as I am a novice programmer I am worried that there might be errors in my code. Would someone that is more experience than I look over my code and let me know if I need to make some changes? The line I am most concerned about contains flags -= SDL_FULLSCREEN, I’m not sure if this is the correct way to remove a Uint32 flag.
Code:
// Cross-platform Toggle FullScreen for an SDL Window
// This code toggles fullscreen on an SDL window using the same parameters as the given window, e.g. window height, width and bpp
#ifndef _SDL_TOGGLE_FS_H
#define _SDL_TOGGLE_FS_H
#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 /* _SDL_TOGGLE_FS_H */------------------------
OS:
Windows XP Profession
Lubuntu/Ubuntu Linux 10.10