test/testdisplayinfo.c
author Philipp Wiesemann <philipp.wiesemann@arcor.de>
Wed, 25 Nov 2015 21:39:28 +0100
changeset 9922 b066d5fd5fa7
parent 9833 c3214bb33a1d
child 9998 f67cf37e9cd4
permissions -rw-r--r--
Replaced tabs with spaces in test programs.
icculus@9800
     1
/*
icculus@9800
     2
  Copyright (C) 1997-2015 Sam Lantinga <slouken@libsdl.org>
icculus@9800
     3
icculus@9800
     4
  This software is provided 'as-is', without any express or implied
icculus@9800
     5
  warranty.  In no event will the authors be held liable for any damages
icculus@9800
     6
  arising from the use of this software.
icculus@9800
     7
icculus@9800
     8
  Permission is granted to anyone to use this software for any purpose,
icculus@9800
     9
  including commercial applications, and to alter it and redistribute it
icculus@9800
    10
  freely.
icculus@9800
    11
*/
icculus@9800
    12
philipp@9802
    13
/* Program to test querying of display info */
icculus@9800
    14
icculus@9800
    15
#include "SDL.h"
icculus@9800
    16
icculus@9800
    17
#include <stdio.h>
icculus@9800
    18
#include <stdlib.h>
icculus@9800
    19
icculus@9800
    20
static void
icculus@9800
    21
print_mode(const char *prefix, const SDL_DisplayMode *mode)
icculus@9800
    22
{
icculus@9800
    23
    if (!mode)
icculus@9800
    24
        return;
icculus@9800
    25
icculus@9800
    26
    SDL_Log("%s: fmt=%s w=%d h=%d refresh=%d\n",
icculus@9800
    27
            prefix, SDL_GetPixelFormatName(mode->format),
icculus@9800
    28
            mode->w, mode->h, mode->refresh_rate);
icculus@9800
    29
}
icculus@9800
    30
icculus@9800
    31
int
icculus@9800
    32
main(int argc, char *argv[])
icculus@9800
    33
{
icculus@9800
    34
    SDL_DisplayMode mode;
icculus@9800
    35
    int num_displays, dpy;
icculus@9800
    36
philipp@9922
    37
    /* Enable standard application logging */
philipp@9922
    38
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
icculus@9800
    39
icculus@9800
    40
    /* Load the SDL library */
icculus@9800
    41
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
icculus@9800
    42
        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
icculus@9800
    43
        return 1;
icculus@9800
    44
    }
icculus@9800
    45
icculus@9800
    46
    SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver());
icculus@9800
    47
    num_displays = SDL_GetNumVideoDisplays();
icculus@9800
    48
icculus@9800
    49
    SDL_Log("See %d displays.\n", num_displays);
icculus@9800
    50
icculus@9800
    51
    for (dpy = 0; dpy < num_displays; dpy++) {
icculus@9800
    52
        const int num_modes = SDL_GetNumDisplayModes(dpy);
icculus@9800
    53
        SDL_Rect rect = { 0, 0, 0, 0 };
icculus@9800
    54
        int m;
icculus@9800
    55
icculus@9800
    56
        SDL_GetDisplayBounds(dpy, &rect);
icculus@9800
    57
        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);
icculus@9800
    58
icculus@9800
    59
        if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) {
icculus@9800
    60
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    CURRENT: failed to query (%s)\n", SDL_GetError());
icculus@9800
    61
        } else {
icculus@9800
    62
            print_mode("CURRENT", &mode);
icculus@9800
    63
        }
icculus@9800
    64
icculus@9800
    65
        if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) {
icculus@9800
    66
            SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    DESKTOP: failed to query (%s)\n", SDL_GetError());
icculus@9800
    67
        } else {
icculus@9800
    68
            print_mode("DESKTOP", &mode);
icculus@9800
    69
        }
icculus@9800
    70
icculus@9800
    71
        for (m = 0; m < num_modes; m++) {
icculus@9800
    72
            if (SDL_GetDisplayMode(dpy, m, &mode) == -1) {
icculus@9800
    73
                SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "    MODE %d: failed to query (%s)\n", m, SDL_GetError());
icculus@9800
    74
            } else {
icculus@9800
    75
                char prefix[64];
icculus@9800
    76
                SDL_snprintf(prefix, sizeof (prefix), "    MODE %d", m);
icculus@9800
    77
                print_mode(prefix, &mode);
icculus@9800
    78
            }
icculus@9800
    79
        }
icculus@9800
    80
icculus@9800
    81
        SDL_Log("\n");
icculus@9800
    82
    }
icculus@9800
    83
icculus@9833
    84
    SDL_Quit();
icculus@9800
    85
    return 0;
icculus@9800
    86
}
icculus@9800
    87
icculus@9800
    88
/* vi: set ts=4 sw=4 expandtab: */
icculus@9800
    89