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

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

Definition at line 32 of file testdisplayinfo.c.

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.

{
int num_displays, dpy;
/* Enable standard application logging */
/* Load the SDL library */
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return 1;
}
SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
num_displays = SDL_GetNumVideoDisplays();
SDL_Log("See %d displays.\n", num_displays);
for (dpy = 0; dpy < num_displays; dpy++) {
const int num_modes = SDL_GetNumDisplayModes(dpy);
SDL_Rect rect = { 0, 0, 0, 0 };
float ddpi, hdpi, vdpi;
int m;
SDL_GetDisplayBounds(dpy, &rect);
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);
if (SDL_GetDisplayDPI(dpy, &ddpi, &hdpi, &vdpi) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DPI: failed to query (%s)\n", SDL_GetError());
} else {
SDL_Log(" DPI: ddpi=%f; hdpi=%f; vdpi=%f\n", ddpi, hdpi, vdpi);
}
if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError());
} else {
print_mode("CURRENT", &mode);
}
if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError());
} else {
print_mode("DESKTOP", &mode);
}
for (m = 0; m < num_modes; m++) {
if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError());
} else {
char prefix[64];
SDL_snprintf(prefix, sizeof (prefix), " MODE %d", m);
print_mode(prefix, &mode);
}
}
SDL_Log("\n");
}
return 0;
}
static void print_mode ( const char *  prefix,
const SDL_DisplayMode mode 
)
static

Definition at line 21 of file testdisplayinfo.c.

References SDL_DisplayMode::format, SDL_DisplayMode::h, SDL_DisplayMode::refresh_rate, SDL_GetPixelFormatName, SDL_Log, and SDL_DisplayMode::w.

Referenced by main().

{
if (!mode)
return;
SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
mode->w, mode->h, mode->refresh_rate);
}