Wiki Page Content

Differences between revisions 13 and 14
Revision 13 as of 2011-06-28 22:16:30
Size: 1543
Editor: SheenaSmith
Comment: update content for consistency - add SDL_GetError() to NULL RVs
Revision 14 as of 2012-05-27 02:23:47
Size: 2662
Editor: ChrisBush
Comment: Code example
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Line 15: Line 14:
== Function Parameters ==
||'''displayIndex''' ||the index of the display to query ||
||'''mode''' ||an [[SDL_DisplayMode]] structure containing the desired display mode ||
||'''closest''' ||an [[SDL_DisplayMode]] structure filled in with the closest match of the available display modes ||
Line 16: Line 19:
== Function Parameters ==
||'''displayIndex'''||the index of the display to query||
||'''mode'''||an [[SDL_DisplayMode]] structure containing the desired display mode||
||'''closest'''||an [[SDL_DisplayMode]] structure filled in with the closest match of the available display modes||
Line 22: Line 21:
Returns the passed in value '''closest''' or NULL if no matching video mode was available; call [[SDL_GetError]]() for more information.  Returns the passed in value '''closest''' or NULL if no matching video mode was available; call [[SDL_GetError]]() for more information.
Line 26: Line 25:
You can add your code example here // Using SDL2's SDL_GetClosestDisplayMode()
#include <SDL2/SDL.h>
#include <cstdio>

int main(int argc, char* argv[]){

  SDL_Init(SDL_INIT_VIDEO);

  // Declare structures to be filled in.
  SDL_DisplayMode target, closest;

  // Set the desired resolution, etc.
  target.w = 600;
  target.h = 500;
  target.format = 0; // don't care
  target.refresh_rate = 0; // don't care
  target.driverdata = 0; // initialize to 0
  printf("Requesting: \t%dx%dpx @ %dhz \n", target.w, target.h, target.refresh_rate);

  // Pass the display mode structures by reference to SDL_GetClosestDisplay
  // and check whether the result is a null pointer.
  if(SDL_GetClosestDisplayMode(0, &target, &closest)==NULL)

    // If the returned pointer is null, no match was found.
    printf("\nNo suitable display mode was found!\n\n");

  else
    // Otherwise, a display mode close to the target is available.
    // Access the SDL_DisplayMode structure to see what was received.
    printf(" Received: \t%dx%dpx @ %dhz \n", closest.w, closest.h, closest.refresh_rate);

  // Clean up and exit the program.
  SDL_Quit();
  return 0;

}
Line 28: Line 62:
Line 33: Line 66:
 .[[SDL_GetDisplayMode]]
 .[[SDL_GetNumDisplayModes]]
 . [[SDL_GetDisplayMode]]
 . [[SDL_GetNumDisplayModes]]
Line 37: Line 70:
[[CategoryAPI]], [[CategoryVideo]] [[CategoryAPI]], !CategoryVideo

SDL_GetClosestDisplayMode

Use this function to get the closest match to the requested display mode.

Syntax

SDL_DisplayMode* SDL_GetClosestDisplayMode(int                    displayIndex,
                                           const SDL_DisplayMode* mode,
                                           SDL_DisplayMode*       closest)

Function Parameters

displayIndex

the index of the display to query

mode

an SDL_DisplayMode structure containing the desired display mode

closest

an SDL_DisplayMode structure 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; call SDL_GetError() for more information.

Code Examples

// Using SDL2's SDL_GetClosestDisplayMode()
#include <SDL2/SDL.h>
#include <cstdio>

int main(int argc, char* argv[]){

  SDL_Init(SDL_INIT_VIDEO);

  // Declare structures to be filled in.
  SDL_DisplayMode target, closest;

  // Set the desired resolution, etc.
  target.w = 600;
  target.h = 500;
  target.format = 0;  // don't care
  target.refresh_rate = 0; // don't care
  target.driverdata   = 0; // initialize to 0
  printf("Requesting: \t%dx%dpx @ %dhz \n", target.w, target.h, target.refresh_rate);

  // Pass the display mode structures by reference to SDL_GetClosestDisplay
  // and check whether the result is a null pointer.
  if(SDL_GetClosestDisplayMode(0, &target, &closest)==NULL)

    // If the returned pointer is null, no match was found.
    printf("\nNo suitable display mode was found!\n\n");

  else
    // Otherwise, a display mode close to the target is available.
    // Access the SDL_DisplayMode structure to see what was received.
    printf("  Received: \t%dx%dpx @ %dhz \n", closest.w, closest.h, closest.refresh_rate);

  // Clean up and exit the program.
  SDL_Quit();
  return 0;

}

Remarks

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 set to 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.


CategoryAPI, CategoryVideo

None: SDL_GetClosestDisplayMode (last edited 2014-01-19 14:02:00 by PhilippWiesemann)

(Page Info.)
Feedback
Please include your contact information if you'd like to receive a reply.
Submit