testdisplayinfo.c
Go to the documentation of this file.
/*
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely.
*/
/* Program to test querying of display info */
#include "SDL.h"
#include <stdio.h>
#include <stdlib.h>
static void
print_mode(const char *prefix, const SDL_DisplayMode *mode)
{
if (!mode)
return;
SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
prefix, SDL_GetPixelFormatName(mode->format),
mode->w, mode->h, mode->refresh_rate);
}
int
main(int argc, char *argv[])
{
SDL_DisplayMode mode;
int num_displays, dpy;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
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");
}
SDL_Quit();
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */
SDL_GetError
#define SDL_GetError
Definition: SDL_dynapi_overrides.h:113
print_mode
static void print_mode(const char *prefix, const SDL_DisplayMode *mode)
Definition: testdisplayinfo.c:21
SDL_GetDisplayMode
#define SDL_GetDisplayMode
Definition: SDL_dynapi_overrides.h:506
SDL_DisplayMode::w
int w
Definition: SDL_video.h:56
dpy
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display dpy)
Definition: SDL_x11sym.h:44
rect
SDL_Rect rect
Definition: testrelative.c:27
m
const GLfloat * m
Definition: SDL_opengl_glext.h:6092
SDL_GetDesktopDisplayMode
#define SDL_GetDesktopDisplayMode
Definition: SDL_dynapi_overrides.h:507
SDL_GetDisplayName
#define SDL_GetDisplayName
Definition: SDL_dynapi_overrides.h:502
SDL_DisplayMode
The structure that defines a display mode.
Definition: SDL_video.h:53
SDL_DisplayMode::refresh_rate
int refresh_rate
Definition: SDL_video.h:58
main
int main(int argc, char *argv[])
Definition: testdisplayinfo.c:32
SDL_LogError
#define SDL_LogError
Definition: SDL_dynapi_overrides.h:36
SDL_GetNumVideoDisplays
#define SDL_GetNumVideoDisplays
Definition: SDL_dynapi_overrides.h:501
SDL_Log
#define SDL_Log
Definition: SDL_dynapi_overrides.h:31
SDL_Quit
#define SDL_Quit
Definition: SDL_dynapi_overrides.h:58
mode
GLenum mode
Definition: SDL_opengl_glext.h:1122
SDL_GetDisplayBounds
#define SDL_GetDisplayBounds
Definition: SDL_dynapi_overrides.h:503
SDL_DisplayMode::h
int h
Definition: SDL_video.h:57
SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
SDL_Rect::x
int x
Definition: SDL_rect.h:66
SDL_Rect::w
int w
Definition: SDL_rect.h:67
SDL_LogSetPriority
#define SDL_LogSetPriority
Definition: SDL_dynapi_overrides.h:236
SDL_GetCurrentVideoDriver
#define SDL_GetCurrentVideoDriver
Definition: SDL_dynapi_overrides.h:500
SDL_Rect::h
int h
Definition: SDL_rect.h:67
SDL_GetDisplayDPI
#define SDL_GetDisplayDPI
Definition: SDL_dynapi_overrides.h:504
SDL_snprintf
#define SDL_snprintf
Definition: SDL_dynapi_overrides.h:40
SDL_Init
#define SDL_Init
Definition: SDL_dynapi_overrides.h:54
SDL_GetNumDisplayModes
#define SDL_GetNumDisplayModes
Definition: SDL_dynapi_overrides.h:505
SDL_DisplayMode::format
Uint32 format
Definition: SDL_video.h:55
SDL.h
SDL_GetCurrentDisplayMode
#define SDL_GetCurrentDisplayMode
Definition: SDL_dynapi_overrides.h:508
SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
SDL_Rect::y
int y
Definition: SDL_rect.h:66
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:78
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:64
SDL_GetPixelFormatName
#define SDL_GetPixelFormatName
Definition: SDL_dynapi_overrides.h:277