Skip to content

Latest commit

 

History

History
96 lines (74 loc) · 2.93 KB

testdisplayinfo.c

File metadata and controls

96 lines (74 loc) · 2.93 KB
 
Jul 15, 2015
Jul 15, 2015
1
/*
Jan 2, 2017
Jan 2, 2017
2
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
Jul 15, 2015
Jul 15, 2015
3
4
5
6
7
8
9
10
11
12
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.
*/
Jul 15, 2015
Jul 15, 2015
13
/* Program to test querying of display info */
Jul 15, 2015
Jul 15, 2015
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#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;
Nov 25, 2015
Nov 25, 2015
37
38
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
Jul 15, 2015
Jul 15, 2015
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* 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 };
Jan 7, 2016
Jan 7, 2016
54
float ddpi, hdpi, vdpi;
Jul 15, 2015
Jul 15, 2015
55
56
57
58
59
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);
Jan 7, 2016
Jan 7, 2016
60
61
62
63
64
65
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);
}
Jul 15, 2015
Jul 15, 2015
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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");
}
Aug 7, 2015
Aug 7, 2015
91
SDL_Quit();
Jul 15, 2015
Jul 15, 2015
92
93
94
95
return 0;
}
/* vi: set ts=4 sw=4 expandtab: */