view test/testwm2.c @ 1718:ed4d4f1ea201 SDL-1.3

Further progress on the new Windows video driver: * SDL_SetModuleHandle() is obsolete, I hope. * SDL 1.3 uses the UNICODE API * I'm ignoring Windows CE for the moment, we'll reevaluate what needs to be different for Windows CE later. * Pulled the stdio redirection from WinMain()
author Sam Lantinga <slouken@libsdl.org>
date Tue, 27 Jun 2006 07:46:36 +0000
parents 3e66ed1690e4
children 5b9f50c957ed
line wrap: on
line source

/* Simple program:  Move N sprites around on the screen as fast as possible */

#include "SDL.h"

#define NUM_WINDOWS 2
#define WINDOW_W    640
#define WINDOW_H    480

static int num_windows;
static SDL_WindowID *windows;

/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void
quit(int rc)
{
    if (windows) {
        SDL_free(windows);
    }
    SDL_Quit();
    exit(rc);
}

int
main(int argc, char *argv[])
{
    int window_w, window_h;
    int i, done;
    SDL_Event event;

    /* Initialize SDL */
    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
        return (1);
    }

    num_windows = NUM_WINDOWS;
    window_w = WINDOW_W;
    window_h = WINDOW_H;
    while (argc > 1) {
        --argc;
        if (strcmp(argv[argc - 1], "-width") == 0) {
            window_w = atoi(argv[argc]);
            --argc;
        } else if (strcmp(argv[argc - 1], "-height") == 0) {
            window_h = atoi(argv[argc]);
            --argc;
        } else {
            fprintf(stderr, "Usage: %s [-width] [-height]\n", argv[0]);
            quit(1);
        }
    }

    /* Set the desktop mode, we don't care what it is */
    if (SDL_SetDisplayMode(NULL) < 0) {
        fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError());
        quit(2);
    }

    /* Create the windows */
    windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows));
    if (!windows) {
        fprintf(stderr, "Out of memory!\n");
        quit(2);
    }
    for (i = 0; i < num_windows; ++i) {
        char title[32];

        SDL_snprintf(title, sizeof(title), "testwm %d", i + 1);
        windows[i] =
            SDL_CreateWindow(title, -1, -1, window_w, window_h,
                             SDL_WINDOW_SHOWN);
        if (!windows[i]) {
            fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
            quit(2);
        }
    }

    /* Loop, blitting sprites and waiting for a keystroke */
    done = 0;
    while (!done) {
        /* Check for events */
        while (SDL_PollEvent(&event)) {
            switch (event.type) {
            case SDL_KEYDOWN:
                /* Any keypress quits the app... */
            case SDL_QUIT:
                done = 1;
                break;
            default:
                break;
            }
        }
    }

    quit(0);
}

/* vi: set ts=4 sw=4 expandtab: */