SDL 2.0
testdisplayinfo.c File Reference
#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
+ Include dependency graph for testdisplayinfo.c:

Go to the source code of this file.

Functions

static void print_mode (const char *prefix, const SDL_DisplayMode *mode)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

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

Definition at line 32 of file testdisplayinfo.c.

33{
35 int num_displays, dpy;
36
37 /* Enable standard application logging */
39
40 /* Load the SDL library */
41 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
42 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
43 return 1;
44 }
45
46 SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
47 num_displays = SDL_GetNumVideoDisplays();
48
49 SDL_Log("See %d displays.\n", num_displays);
50
51 for (dpy = 0; dpy < num_displays; dpy++) {
52 const int num_modes = SDL_GetNumDisplayModes(dpy);
53 SDL_Rect rect = { 0, 0, 0, 0 };
54 float ddpi, hdpi, vdpi;
55 int m;
56
58 SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes);
59
60 if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
61 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
62 } else {
63 SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
64 }
65
66 if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
67 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
68 } else {
69 print_mode("CURRENT", &mode);
70 }
71
72 if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
73 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError());
74 } else {
75 print_mode("DESKTOP", &mode);
76 }
77
78 for (m = 0; m < num_modes; m++) {
79 if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
80 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError());
81 } else {
82 char prefix[64];
83 SDL_snprintf(prefix, sizeof (prefix), " MODE %d", m);
84 print_mode(prefix, &mode);
85 }
86 }
87
88 SDL_Log("\n");
89 }
90
91 SDL_Quit();
92 return 0;
93}
#define SDL_INIT_VIDEO
Definition: SDL.h:79
#define SDL_GetError
#define SDL_GetCurrentVideoDriver
#define SDL_GetDisplayName
#define SDL_GetDisplayDPI
#define SDL_GetNumDisplayModes
#define SDL_LogSetPriority
#define SDL_LogError
#define SDL_GetDisplayMode
#define SDL_Quit
#define SDL_GetDesktopDisplayMode
#define SDL_GetCurrentDisplayMode
#define SDL_Init
#define SDL_GetNumVideoDisplays
#define SDL_GetDisplayBounds
#define SDL_Log
#define SDL_snprintf
@ SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
@ SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
const GLfloat * m
GLenum mode
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display dpy)
Definition: SDL_x11sym.h:44
The structure that defines a display mode.
Definition: SDL_video.h:54
A rectangle, with the origin at the upper left (integer).
Definition: SDL_rect.h:78
int h
Definition: SDL_rect.h:80
int w
Definition: SDL_rect.h:80
int y
Definition: SDL_rect.h:79
int x
Definition: SDL_rect.h:79
static void print_mode(const char *prefix, const SDL_DisplayMode *mode)
SDL_Rect rect
Definition: testrelative.c:27

References dpy, SDL_Rect::h, print_mode(), rect, SDL_GetCurrentDisplayMode, SDL_GetCurrentVideoDriver, SDL_GetDesktopDisplayMode, SDL_GetDisplayBounds, SDL_GetDisplayDPI, SDL_GetDisplayMode, SDL_GetDisplayName, SDL_GetError, SDL_GetNumDisplayModes, SDL_GetNumVideoDisplays, SDL_Init, SDL_INIT_VIDEO, SDL_Log, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_Quit, SDL_snprintf, SDL_Rect::w, SDL_Rect::x, and SDL_Rect::y.

◆ print_mode()

static void print_mode ( const char *  prefix,
const SDL_DisplayMode mode 
)
static

Definition at line 21 of file testdisplayinfo.c.

22{
23 if (!mode)
24 return;
25
26 SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
27 prefix, SDL_GetPixelFormatName(mode->format),
28 mode->w, mode->h, mode->refresh_rate);
29}
#define SDL_GetPixelFormatName

References SDL_GetPixelFormatName, and SDL_Log.

Referenced by main().