SDL_GetClosestDisplayMode

Name

SDL_GetClosestDisplayMode -- Get the closest match to the requested display mode.

Synopsis

#include "SDL_video.h"

SDL_DisplayMode * SDL_GetClosestDisplayMode (
    const SDL_DisplayMode * mode,
    SDL_DisplayMode * closest
);

Description

SDL_GetClosestDisplayMode gets the closest match to the requested display mode.

The available display modes are scanned, and 'closest' is filled in with the closest mode matching the requested mode and returned. The mode format and refresh_rate default to the desktop mode if they are 0. The modes are scanned with size being first priority, format being second priority, and finally checking the refresh_rate. If all the available modes are too small, then NULL is returned.

Parameters

mode

The desired display mode.

closest

A pointer to a display mode to be filled in with the closest match of the available display modes.

Return Value

Returns the passed in value 'closest', or NULL if no matching video mode was available.

Example

   1 #include "SDL.h"
   2 #include <stdio.h>
   3 
   4 int main(int argc, char** argv) {
   5   SDL_DisplayMode desiredmode = {0}, actualmode;
   6   
   7   if (argc < 3) {
   8     printf("Finds the closest display mode available to SDL.\n"
   9            "Syntax:  %s width height[ refresh]\n"
  10            "Where width and height are the dimensions in pixels and "
  11            "refresh is the refresh rate of the desired video mode.\n", argv[0]);
  12     return 1;
  13   }
  14   desiredmode.w = atoi(argv[1]);
  15   desiredmode.h = atoi(argv[2]);
  16   if (argc > 3)
  17     desiredmode.refresh_rate = atoi(argv[3]);
  18   
  19   if (SDL_Init(SDL_INIT_VIDEO) != 0) {
  20     printf("Error initializing SDL:  %s\n", SDL_GetError());
  21     return 2;
  22   }
  23   atexit (SDL_Quit);
  24   
  25   if (SDL_GetClosestDisplayMode(&desiredmode, &actualmode) == NULL) {
  26     printf("Unable to find suitable display mode\n");
  27     return 3;
  28   }
  29   
  30   printf("Found matching display mode:  %d x %d (%d Hz)\n",
  31          actualmode.w, actualmode.h, actualmode.refresh_rate);
  32   return 0;
  33 }

See Also

SDL_GetNumDisplayModes, SDL_GetDisplayMode


CategorySDL13API CategorySDL13APIVideo

SDL-1.3/SDL_GetClosestDisplayMode (last edited 2009-07-30 07:22:58 by KenBull)