SDL_SetFullscreenDisplayMode

Name

SDL_SetFullscreenDisplayMode -- Set the fullscreen display mode.

Synopsis

#include "SDL_video.h"

int SDL_SetFullscreenDisplayMode (const SDL_DisplayMode * mode);

Description

SDL_SetFullscreenDisplayMode sets the display mode used when a fullscreen window is visible on the currently selected display.

Parameters

mode

The mode to use, or NULL for the desktop mode.

Return Value

Returns 0 on success, or -1 if setting the display mode failed.

Example

   1 #include "SDL.h"
   2 #include <stdio.h>
   3 
   4 int main(int argc, char** argv) {
   5   SDL_DisplayMode mode = {0};
   6   SDL_WindowID window;
   7   SDL_Event event;
   8   int fullscreen = 0;
   9   
  10   if (SDL_Init(SDL_INIT_VIDEO) != 0) {
  11     printf("Error initializing SDL:  %s\n", SDL_GetError());
  12     return 1;
  13   }
  14   atexit(SDL_Quit);
  15   
  16   window = SDL_CreateWindow("Example", 
  17     SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
  18     512, 384, SDL_WINDOW_SHOWN|(fullscreen? SDL_WINDOW_FULLSCREEN: 0));
  19   if (window == 0) {
  20     printf("Unable to create window:  %s\n", SDL_GetError());
  21     return 2;
  22   }
  23   
  24   mode.format = SDL_PIXELFORMAT_RGB888;
  25   mode.w = 640;
  26   mode.h = 480;
  27   
  28   SDL_SetFullscreenDisplayMode(&mode);
  29   
  30   while(SDL_WaitEvent(&event)) {
  31     switch (event.type) {
  32       case SDL_QUIT:
  33         return 0;
  34       case SDL_KEYDOWN:
  35         switch (event.key.keysym.sym) {
  36           case 'f':
  37             fullscreen = !fullscreen;
  38             if (SDL_SetWindowFullscreen(event.key.windowID, fullscreen) != 0) {
  39               printf ("Unable to switch window to fullscreen mode:  %s\n", SDL_GetError());
  40               SDL_ClearError();
  41               fullscreen = !fullscreen;
  42             }
  43             break;
  44           case 'q':
  45           case SDLK_ESCAPE:
  46             return 0;
  47         }
  48         break;
  49       case SDL_WINDOWEVENT:
  50         switch (event.window.event) {
  51           case SDL_WINDOWEVENT_RESIZED:
  52             printf("Window %u resized to %d x %d.\n", event.window.windowID, event.window.data1, event.window.data2);
  53             break;
  54           case SDL_WINDOWEVENT_CLOSE:
  55             SDL_HideWindow(event.window.windowID);
  56             return 0;
  57         }
  58         break;
  59     }
  60   }
  61   
  62   printf("SDL error in event loop:  %s\n", SDL_GetError());
  63   return 3;
  64 }

See Also

SDL_SetWindowFullscreen, SDL_GetFullscreenDisplayMode


CategorySDL13API CategorySDL13APIVideo

SDL-1.3/SDL_SetFullscreenDisplayMode (last edited 2009-07-30 09:39:23 by KenBull)