SDL_GetDisplayMode
Name
SDL_GetDisplayMode -- Fill in information about a specific display mode.
Synopsis
#include "SDL_video.h" int SDL_GetDisplayMode (int index, SDL_DisplayMode * mode);
Description
SDL_GetDisplayMode fills in information about a specific display mode.
Parameters
index |
The index of the display mode to retrieve information about. |
mode |
A pointer to an SDL_DisplayMode structure to hold information about the display mode. |
Return Value
Returns 0 if successful, or -1 if index is out of range.
Note: The display modes are sorted in this priority:
bits per pixel -> more colors to fewer colors
width -> largest to smallest
height -> largest to smallest
refresh rate -> highest to lowest
Example
1 #include "SDL.h"
2 #include <stdio.h>
3
4 int main(int argc, char** argv) {
5 int numdisplays, defaultdisplay, i;
6 int nummodes, j;
7 SDL_DisplayMode mode;
8
9 if (SDL_Init(SDL_INIT_VIDEO) != 0) {
10 printf("Error initializing SDL: %s\n", SDL_GetError());
11 return 1;
12 }
13 atexit(SDL_Quit);
14
15 numdisplays = SDL_GetNumVideoDisplays();
16 defaultdisplay = SDL_GetCurrentVideoDisplay();
17 printf("Currently using display %d.\n", defaultdisplay);
18
19 for (i = 0; i < numdisplays; ++i) {
20 printf("\nEnumerating modes for display %d\n", i);
21 SDL_SelectVideoDisplay(i);
22 nummodes = SDL_GetNumDisplayModes();
23 for (j = 0; j < nummodes; ++j) {
24 SDL_GetDisplayMode(j, &mode);
25 printf(" Mode %d: %dx%d %dHz %d bpp\n", j, mode.w, mode.h, mode.refresh_rate, SDL_BITSPERPIXEL(mode.format));
26 }
27 printf(" %d modes.\n", nummodes);
28 }
29 SDL_SelectVideoDisplay(defaultdisplay);
30
31 printf("\n%d displays.\n", numdisplays);
32 }
See Also
SDL_GetNumDisplayModes, SDL_DisplayMode
