test/testwm2.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 26 Jun 2006 13:56:56 +0000
branchSDL-1.3
changeset 1712 931d111e737a
child 1713 3e66ed1690e4
permissions -rw-r--r--
Started framework for Windows video driver
slouken@1712
     1
/* Simple program:  Move N sprites around on the screen as fast as possible */
slouken@1712
     2
slouken@1712
     3
#include "SDL.h"
slouken@1712
     4
slouken@1712
     5
#define NUM_WINDOWS 2
slouken@1712
     6
#define WINDOW_W    640
slouken@1712
     7
#define WINDOW_H    480
slouken@1712
     8
slouken@1712
     9
static int num_windows;
slouken@1712
    10
static SDL_WindowID *windows;
slouken@1712
    11
slouken@1712
    12
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
slouken@1712
    13
static void
slouken@1712
    14
quit(int rc)
slouken@1712
    15
{
slouken@1712
    16
    if (windows) {
slouken@1712
    17
        SDL_free(windows);
slouken@1712
    18
    }
slouken@1712
    19
    SDL_Quit();
slouken@1712
    20
    exit(rc);
slouken@1712
    21
}
slouken@1712
    22
slouken@1712
    23
int
slouken@1712
    24
main(int argc, char *argv[])
slouken@1712
    25
{
slouken@1712
    26
    int window_w, window_h;
slouken@1712
    27
    int i, done;
slouken@1712
    28
    SDL_Event event;
slouken@1712
    29
slouken@1712
    30
    /* Initialize SDL */
slouken@1712
    31
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
slouken@1712
    32
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
slouken@1712
    33
        return (1);
slouken@1712
    34
    }
slouken@1712
    35
slouken@1712
    36
    num_windows = NUM_WINDOWS;
slouken@1712
    37
    window_w = WINDOW_W;
slouken@1712
    38
    window_h = WINDOW_H;
slouken@1712
    39
    while (argc > 1) {
slouken@1712
    40
        --argc;
slouken@1712
    41
        if (strcmp(argv[argc - 1], "-width") == 0) {
slouken@1712
    42
            window_w = atoi(argv[argc]);
slouken@1712
    43
            --argc;
slouken@1712
    44
        } else if (strcmp(argv[argc - 1], "-height") == 0) {
slouken@1712
    45
            window_h = atoi(argv[argc]);
slouken@1712
    46
            --argc;
slouken@1712
    47
        } else {
slouken@1712
    48
            fprintf(stderr,
slouken@1712
    49
                    "Usage: %s [-width] [-height]\n", argv[0]);
slouken@1712
    50
            quit(1);
slouken@1712
    51
        }
slouken@1712
    52
    }
slouken@1712
    53
slouken@1712
    54
    /* Set the desktop mode, we don't care what it is */
slouken@1712
    55
    if (SDL_SetDisplayMode(NULL) < 0) {
slouken@1712
    56
        fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError());
slouken@1712
    57
        quit(2);
slouken@1712
    58
    }
slouken@1712
    59
slouken@1712
    60
    /* Create the windows */
slouken@1712
    61
    windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows));
slouken@1712
    62
    if (!windows) {
slouken@1712
    63
        fprintf(stderr, "Out of memory!\n");
slouken@1712
    64
        quit(2);
slouken@1712
    65
    }
slouken@1712
    66
    for (i = 0; i < num_windows; ++i) {
slouken@1712
    67
        char title[32];
slouken@1712
    68
slouken@1712
    69
        SDL_snprintf(title, sizeof(title), "testwm %d", i + 1);
slouken@1712
    70
        windows[i] =
slouken@1712
    71
            SDL_CreateWindow(title, -1, -1, window_w, window_h,
slouken@1712
    72
                             SDL_WINDOW_SHOWN);
slouken@1712
    73
        if (!windows[i]) {
slouken@1712
    74
            fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
slouken@1712
    75
            quit(2);
slouken@1712
    76
        }
slouken@1712
    77
    }
slouken@1712
    78
slouken@1712
    79
    /* Loop, blitting sprites and waiting for a keystroke */
slouken@1712
    80
    done = 0;
slouken@1712
    81
    while (!done) {
slouken@1712
    82
        /* Check for events */
slouken@1712
    83
        while (SDL_PollEvent(&event)) {
slouken@1712
    84
            switch (event.type) {
slouken@1712
    85
            case SDL_KEYDOWN:
slouken@1712
    86
                /* Any keypress quits the app... */
slouken@1712
    87
            case SDL_QUIT:
slouken@1712
    88
                done = 1;
slouken@1712
    89
                break;
slouken@1712
    90
            default:
slouken@1712
    91
                break;
slouken@1712
    92
            }
slouken@1712
    93
        }
slouken@1712
    94
    }
slouken@1712
    95
slouken@1712
    96
    quit(0);
slouken@1712
    97
}
slouken@1712
    98
slouken@1712
    99
/* vi: set ts=4 sw=4 expandtab: */