test/common.c
author David Ludwig <dludwig@pobox.com>
Tue, 12 Feb 2013 12:57:06 -0500
changeset 8424 3cf9501008f1
parent 6602 533131e24aeb
child 6783 001f59dc43be
permissions -rw-r--r--
WinRT: fixed bug: SDL_CreateWindow wouldn't work after an initial window was created + destroyed
slouken@5535
     1
/*
slouken@5535
     2
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     3
slouken@5535
     4
  This software is provided 'as-is', without any express or implied
slouken@5535
     5
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     6
  arising from the use of this software.
slouken@5535
     7
slouken@5535
     8
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
     9
  including commercial applications, and to alter it and redistribute it
slouken@5535
    10
  freely.
slouken@5535
    11
*/
slouken@1914
    12
slouken@1914
    13
/* A simple test program framework */
slouken@1914
    14
slouken@1914
    15
#include <stdio.h>
slouken@1914
    16
slouken@1914
    17
#include "common.h"
slouken@1914
    18
slouken@1914
    19
#define VIDEO_USAGE \
slouken@5234
    20
"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--log all|error|system|audio|video|render|input] [--display N] [--fullscreen | --windows N] [--title title] [--icon icon.bmp] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
slouken@1914
    21
slouken@1914
    22
#define AUDIO_USAGE \
slouken@1914
    23
"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
slouken@1914
    24
slouken@1914
    25
CommonState *
slouken@1914
    26
CommonCreateState(char **argv, Uint32 flags)
slouken@1914
    27
{
slouken@1914
    28
    CommonState *state = SDL_calloc(1, sizeof(*state));
slouken@1914
    29
    if (!state) {
slouken@1914
    30
        SDL_OutOfMemory();
slouken@1914
    31
        return NULL;
slouken@1914
    32
    }
slouken@1914
    33
slouken@1914
    34
    /* Initialize some defaults */
slouken@1914
    35
    state->argv = argv;
slouken@1914
    36
    state->flags = flags;
slouken@5517
    37
#ifdef __NDS__
slouken@5517
    38
    state->window_title = "";
slouken@5517
    39
#else
slouken@1914
    40
    state->window_title = argv[0];
slouken@5517
    41
#endif
slouken@3500
    42
    state->window_flags = 0;
slouken@1914
    43
    state->window_x = SDL_WINDOWPOS_UNDEFINED;
slouken@1914
    44
    state->window_y = SDL_WINDOWPOS_UNDEFINED;
lestat@3194
    45
    state->window_w = DEFAULT_WINDOW_WIDTH;
lestat@3194
    46
    state->window_h = DEFAULT_WINDOW_HEIGHT;
slouken@1914
    47
    state->num_windows = 1;
slouken@1914
    48
    state->audiospec.freq = 22050;
slouken@1914
    49
    state->audiospec.format = AUDIO_S16;
slouken@1914
    50
    state->audiospec.channels = 2;
slouken@1914
    51
    state->audiospec.samples = 2048;
lestat@3408
    52
lestat@3408
    53
    /* Set some very sane GL defaults */
lestat@3408
    54
    state->gl_red_size = 3;
lestat@3408
    55
    state->gl_green_size = 3;
lestat@3408
    56
    state->gl_blue_size = 2;
lestat@3408
    57
    state->gl_alpha_size = 0;
lestat@3408
    58
    state->gl_buffer_size = 0;
lestat@3408
    59
    state->gl_depth_size = 16;
lestat@3408
    60
    state->gl_stencil_size = 0;
lestat@3408
    61
    state->gl_double_buffer = 1;
lestat@3408
    62
    state->gl_accum_red_size = 0;
lestat@3408
    63
    state->gl_accum_green_size = 0;
lestat@3408
    64
    state->gl_accum_blue_size = 0;
lestat@3408
    65
    state->gl_accum_alpha_size = 0;
lestat@3408
    66
    state->gl_stereo = 0;
lestat@3408
    67
    state->gl_multisamplebuffers = 0;
lestat@3408
    68
    state->gl_multisamplesamples = 0;
lestat@3408
    69
    state->gl_retained_backing = 1;
slouken@3571
    70
    state->gl_accelerated = -1;
lestat@3408
    71
slouken@1914
    72
    return state;
slouken@1914
    73
}
slouken@1914
    74
slouken@1914
    75
int
slouken@1914
    76
CommonArg(CommonState * state, int index)
slouken@1914
    77
{
slouken@1914
    78
    char **argv = state->argv;
slouken@1914
    79
slouken@5517
    80
#ifdef __NDS__
slouken@5517
    81
    return 0;
slouken@5517
    82
#endif
slouken@5517
    83
slouken@1914
    84
    if (SDL_strcasecmp(argv[index], "--video") == 0) {
slouken@1914
    85
        ++index;
slouken@1914
    86
        if (!argv[index]) {
slouken@1914
    87
            return -1;
slouken@1914
    88
        }
slouken@1914
    89
        state->videodriver = argv[index];
slouken@1914
    90
        return 2;
slouken@1914
    91
    }
slouken@1914
    92
    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
slouken@1914
    93
        ++index;
slouken@1914
    94
        if (!argv[index]) {
slouken@1914
    95
            return -1;
slouken@1914
    96
        }
slouken@1914
    97
        state->renderdriver = argv[index];
slouken@1914
    98
        return 2;
slouken@1914
    99
    }
slouken@1914
   100
    if (SDL_strcasecmp(argv[index], "--info") == 0) {
slouken@1914
   101
        ++index;
slouken@1914
   102
        if (!argv[index]) {
slouken@1914
   103
            return -1;
slouken@1914
   104
        }
slouken@1914
   105
        if (SDL_strcasecmp(argv[index], "all") == 0) {
slouken@1914
   106
            state->verbose |=
slouken@1914
   107
                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
slouken@1914
   108
                 VERBOSE_EVENT);
slouken@1914
   109
            return 2;
slouken@1914
   110
        }
slouken@1914
   111
        if (SDL_strcasecmp(argv[index], "video") == 0) {
slouken@1914
   112
            state->verbose |= VERBOSE_VIDEO;
slouken@1914
   113
            return 2;
slouken@1914
   114
        }
slouken@1914
   115
        if (SDL_strcasecmp(argv[index], "modes") == 0) {
slouken@1914
   116
            state->verbose |= VERBOSE_MODES;
slouken@1914
   117
            return 2;
slouken@1914
   118
        }
slouken@1914
   119
        if (SDL_strcasecmp(argv[index], "render") == 0) {
slouken@1914
   120
            state->verbose |= VERBOSE_RENDER;
slouken@1914
   121
            return 2;
slouken@1914
   122
        }
slouken@1914
   123
        if (SDL_strcasecmp(argv[index], "event") == 0) {
slouken@1914
   124
            state->verbose |= VERBOSE_EVENT;
slouken@1914
   125
            return 2;
slouken@1914
   126
        }
slouken@1914
   127
        return -1;
slouken@1914
   128
    }
slouken@5234
   129
    if (SDL_strcasecmp(argv[index], "--log") == 0) {
slouken@5234
   130
        ++index;
slouken@5234
   131
        if (!argv[index]) {
slouken@5234
   132
            return -1;
slouken@5234
   133
        }
slouken@5234
   134
        if (SDL_strcasecmp(argv[index], "all") == 0) {
slouken@5234
   135
            SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
slouken@5234
   136
            return 2;
slouken@5234
   137
        }
slouken@5234
   138
        if (SDL_strcasecmp(argv[index], "error") == 0) {
slouken@5234
   139
            SDL_LogSetPriority(SDL_LOG_CATEGORY_ERROR, SDL_LOG_PRIORITY_VERBOSE);
slouken@5234
   140
            return 2;
slouken@5234
   141
        }
slouken@5234
   142
        if (SDL_strcasecmp(argv[index], "system") == 0) {
slouken@5234
   143
            SDL_LogSetPriority(SDL_LOG_CATEGORY_SYSTEM, SDL_LOG_PRIORITY_VERBOSE);
slouken@5234
   144
            return 2;
slouken@5234
   145
        }
slouken@5234
   146
        if (SDL_strcasecmp(argv[index], "audio") == 0) {
slouken@5234
   147
            SDL_LogSetPriority(SDL_LOG_CATEGORY_AUDIO, SDL_LOG_PRIORITY_VERBOSE);
slouken@5234
   148
            return 2;
slouken@5234
   149
        }
slouken@5234
   150
        if (SDL_strcasecmp(argv[index], "video") == 0) {
slouken@5234
   151
            SDL_LogSetPriority(SDL_LOG_CATEGORY_VIDEO, SDL_LOG_PRIORITY_VERBOSE);
slouken@5234
   152
            return 2;
slouken@5234
   153
        }
slouken@5234
   154
        if (SDL_strcasecmp(argv[index], "render") == 0) {
slouken@5234
   155
            SDL_LogSetPriority(SDL_LOG_CATEGORY_RENDER, SDL_LOG_PRIORITY_VERBOSE);
slouken@5234
   156
            return 2;
slouken@5234
   157
        }
slouken@5234
   158
        if (SDL_strcasecmp(argv[index], "input") == 0) {
slouken@5234
   159
            SDL_LogSetPriority(SDL_LOG_CATEGORY_INPUT, SDL_LOG_PRIORITY_VERBOSE);
slouken@5234
   160
            return 2;
slouken@5234
   161
        }
slouken@5234
   162
        return -1;
slouken@5234
   163
    }
slouken@1914
   164
    if (SDL_strcasecmp(argv[index], "--display") == 0) {
slouken@1914
   165
        ++index;
slouken@1914
   166
        if (!argv[index]) {
slouken@1914
   167
            return -1;
slouken@1914
   168
        }
slouken@1914
   169
        state->display = SDL_atoi(argv[index]);
slouken@5247
   170
        if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
slouken@5247
   171
            state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
slouken@5247
   172
            state->window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->display);
slouken@5247
   173
        }
slouken@5304
   174
        if (SDL_WINDOWPOS_ISCENTERED(state->window_x)) {
slouken@5304
   175
            state->window_x = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
slouken@5304
   176
            state->window_y = SDL_WINDOWPOS_CENTERED_DISPLAY(state->display);
slouken@5304
   177
        }
slouken@1914
   178
        return 2;
slouken@1914
   179
    }
slouken@1914
   180
    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
slouken@1914
   181
        state->window_flags |= SDL_WINDOW_FULLSCREEN;
slouken@1914
   182
        state->num_windows = 1;
slouken@1914
   183
        return 1;
slouken@1914
   184
    }
slouken@1914
   185
    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
slouken@1914
   186
        ++index;
slouken@1916
   187
        if (!argv[index] || !SDL_isdigit(*argv[index])) {
slouken@1914
   188
            return -1;
slouken@1914
   189
        }
slouken@1914
   190
        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
slouken@1914
   191
            state->num_windows = SDL_atoi(argv[index]);
slouken@1914
   192
        }
slouken@1914
   193
        return 2;
slouken@1914
   194
    }
slouken@1914
   195
    if (SDL_strcasecmp(argv[index], "--title") == 0) {
slouken@1914
   196
        ++index;
slouken@1914
   197
        if (!argv[index]) {
slouken@1914
   198
            return -1;
slouken@1914
   199
        }
slouken@1914
   200
        state->window_title = argv[index];
slouken@1914
   201
        return 2;
slouken@1914
   202
    }
slouken@4527
   203
    if (SDL_strcasecmp(argv[index], "--icon") == 0) {
slouken@4527
   204
        ++index;
slouken@4527
   205
        if (!argv[index]) {
slouken@4527
   206
            return -1;
slouken@4527
   207
        }
slouken@4527
   208
        state->window_icon = argv[index];
slouken@4527
   209
        return 2;
slouken@4527
   210
    }
slouken@1914
   211
    if (SDL_strcasecmp(argv[index], "--center") == 0) {
slouken@1914
   212
        state->window_x = SDL_WINDOWPOS_CENTERED;
slouken@1914
   213
        state->window_y = SDL_WINDOWPOS_CENTERED;
slouken@1914
   214
        return 1;
slouken@1914
   215
    }
slouken@1914
   216
    if (SDL_strcasecmp(argv[index], "--position") == 0) {
slouken@1914
   217
        char *x, *y;
slouken@1914
   218
        ++index;
slouken@1914
   219
        if (!argv[index]) {
slouken@1914
   220
            return -1;
slouken@1914
   221
        }
slouken@1914
   222
        x = argv[index];
slouken@1914
   223
        y = argv[index];
slouken@1914
   224
        while (*y && *y != ',') {
slouken@1914
   225
            ++y;
slouken@1914
   226
        }
slouken@1914
   227
        if (!*y) {
slouken@1914
   228
            return -1;
slouken@1914
   229
        }
slouken@1914
   230
        *y++ = '\0';
slouken@1914
   231
        state->window_x = SDL_atoi(x);
slouken@1914
   232
        state->window_y = SDL_atoi(y);
slouken@1914
   233
        return 2;
slouken@1914
   234
    }
slouken@1914
   235
    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
slouken@1914
   236
        char *w, *h;
slouken@1914
   237
        ++index;
slouken@1914
   238
        if (!argv[index]) {
slouken@1914
   239
            return -1;
slouken@1914
   240
        }
slouken@1914
   241
        w = argv[index];
slouken@1914
   242
        h = argv[index];
slouken@1914
   243
        while (*h && *h != 'x') {
slouken@1914
   244
            ++h;
slouken@1914
   245
        }
slouken@1914
   246
        if (!*h) {
slouken@1914
   247
            return -1;
slouken@1914
   248
        }
slouken@1914
   249
        *h++ = '\0';
slouken@1914
   250
        state->window_w = SDL_atoi(w);
slouken@1914
   251
        state->window_h = SDL_atoi(h);
slouken@1914
   252
        return 2;
slouken@1914
   253
    }
slouken@2209
   254
    if (SDL_strcasecmp(argv[index], "--depth") == 0) {
slouken@2209
   255
        ++index;
slouken@2209
   256
        if (!argv[index]) {
slouken@2209
   257
            return -1;
slouken@2209
   258
        }
slouken@2209
   259
        state->depth = SDL_atoi(argv[index]);
slouken@2209
   260
        return 2;
slouken@2209
   261
    }
slouken@1914
   262
    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
slouken@1914
   263
        ++index;
slouken@1914
   264
        if (!argv[index]) {
slouken@1914
   265
            return -1;
slouken@1914
   266
        }
slouken@1914
   267
        state->refresh_rate = SDL_atoi(argv[index]);
slouken@1914
   268
        return 2;
slouken@1914
   269
    }
slouken@1914
   270
    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
slouken@1965
   271
        state->render_flags |= SDL_RENDERER_PRESENTVSYNC;
slouken@1914
   272
        return 1;
slouken@1914
   273
    }
slouken@1914
   274
    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
slouken@1914
   275
        state->window_flags |= SDL_WINDOW_BORDERLESS;
slouken@1914
   276
        return 1;
slouken@1914
   277
    }
slouken@1914
   278
    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
slouken@1914
   279
        state->window_flags |= SDL_WINDOW_RESIZABLE;
slouken@1914
   280
        return 1;
slouken@1914
   281
    }
slouken@1914
   282
    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
slouken@1914
   283
        state->window_flags |= SDL_WINDOW_MINIMIZED;
slouken@1914
   284
        return 1;
slouken@1914
   285
    }
slouken@1914
   286
    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
slouken@1914
   287
        state->window_flags |= SDL_WINDOW_MAXIMIZED;
slouken@1914
   288
        return 1;
slouken@1914
   289
    }
slouken@1914
   290
    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
slouken@1914
   291
        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
slouken@1914
   292
        return 1;
slouken@1914
   293
    }
slouken@1914
   294
    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
slouken@1914
   295
        ++index;
slouken@1914
   296
        if (!argv[index]) {
slouken@1914
   297
            return -1;
slouken@1914
   298
        }
slouken@1914
   299
        state->audiospec.freq = SDL_atoi(argv[index]);
slouken@1914
   300
        return 2;
slouken@1914
   301
    }
slouken@1914
   302
    if (SDL_strcasecmp(argv[index], "--format") == 0) {
slouken@1914
   303
        ++index;
slouken@1914
   304
        if (!argv[index]) {
slouken@1914
   305
            return -1;
slouken@1914
   306
        }
slouken@1914
   307
        if (SDL_strcasecmp(argv[index], "U8") == 0) {
slouken@1914
   308
            state->audiospec.format = AUDIO_U8;
slouken@1914
   309
            return 2;
slouken@1914
   310
        }
slouken@1914
   311
        if (SDL_strcasecmp(argv[index], "S8") == 0) {
slouken@1914
   312
            state->audiospec.format = AUDIO_S8;
slouken@1914
   313
            return 2;
slouken@1914
   314
        }
slouken@1914
   315
        if (SDL_strcasecmp(argv[index], "U16") == 0) {
slouken@1914
   316
            state->audiospec.format = AUDIO_U16;
slouken@1914
   317
            return 2;
slouken@1914
   318
        }
slouken@1914
   319
        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
slouken@1914
   320
            state->audiospec.format = AUDIO_U16LSB;
slouken@1914
   321
            return 2;
slouken@1914
   322
        }
slouken@1914
   323
        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
slouken@1914
   324
            state->audiospec.format = AUDIO_U16MSB;
slouken@1914
   325
            return 2;
slouken@1914
   326
        }
slouken@1914
   327
        if (SDL_strcasecmp(argv[index], "S16") == 0) {
slouken@1914
   328
            state->audiospec.format = AUDIO_S16;
slouken@1914
   329
            return 2;
slouken@1914
   330
        }
slouken@1914
   331
        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
slouken@1914
   332
            state->audiospec.format = AUDIO_S16LSB;
slouken@1914
   333
            return 2;
slouken@1914
   334
        }
slouken@1914
   335
        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
slouken@1914
   336
            state->audiospec.format = AUDIO_S16MSB;
slouken@1914
   337
            return 2;
slouken@1914
   338
        }
slouken@1914
   339
        return -1;
slouken@1914
   340
    }
slouken@1914
   341
    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
slouken@1914
   342
        ++index;
slouken@1914
   343
        if (!argv[index]) {
slouken@1914
   344
            return -1;
slouken@1914
   345
        }
bob@2185
   346
        state->audiospec.channels = (Uint8) SDL_atoi(argv[index]);
slouken@1914
   347
        return 2;
slouken@1914
   348
    }
slouken@1914
   349
    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
slouken@1914
   350
        ++index;
slouken@1914
   351
        if (!argv[index]) {
slouken@1914
   352
            return -1;
slouken@1914
   353
        }
bob@2185
   354
        state->audiospec.samples = (Uint16) SDL_atoi(argv[index]);
slouken@1914
   355
        return 2;
slouken@1914
   356
    }
slouken@1914
   357
    if ((SDL_strcasecmp(argv[index], "-h") == 0)
slouken@1914
   358
        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
slouken@1914
   359
        /* Print the usage message */
slouken@1914
   360
        return -1;
slouken@1914
   361
    }
slouken@6175
   362
    if (SDL_strcmp(argv[index], "-NSDocumentRevisionsDebugMode") == 0) {
slouken@6175
   363
	/* Debug flag sent by Xcode */
slouken@6175
   364
        return 2;
slouken@6175
   365
    }
slouken@1914
   366
    return 0;
slouken@1914
   367
}
slouken@1914
   368
slouken@1914
   369
const char *
slouken@1914
   370
CommonUsage(CommonState * state)
slouken@1914
   371
{
slouken@1914
   372
    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
slouken@1914
   373
    case SDL_INIT_VIDEO:
slouken@1914
   374
        return VIDEO_USAGE;
slouken@1914
   375
    case SDL_INIT_AUDIO:
slouken@1914
   376
        return AUDIO_USAGE;
slouken@1914
   377
    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
slouken@1914
   378
        return VIDEO_USAGE " " AUDIO_USAGE;
slouken@1914
   379
    default:
slouken@1914
   380
        return "";
slouken@1914
   381
    }
slouken@1914
   382
}
slouken@1914
   383
slouken@1914
   384
static void
slouken@1914
   385
PrintRendererFlag(Uint32 flag)
slouken@1914
   386
{
slouken@1914
   387
    switch (flag) {
slouken@1965
   388
    case SDL_RENDERER_PRESENTVSYNC:
slouken@1914
   389
        fprintf(stderr, "PresentVSync");
slouken@1914
   390
        break;
slouken@1965
   391
    case SDL_RENDERER_ACCELERATED:
slouken@1921
   392
        fprintf(stderr, "Accelerated");
slouken@1921
   393
        break;
slouken@1914
   394
    default:
slouken@1914
   395
        fprintf(stderr, "0x%8.8x", flag);
slouken@1914
   396
        break;
slouken@1914
   397
    }
slouken@1914
   398
}
slouken@1914
   399
slouken@1914
   400
static void
slouken@1914
   401
PrintPixelFormat(Uint32 format)
slouken@1914
   402
{
slouken@1914
   403
    switch (format) {
slouken@1965
   404
    case SDL_PIXELFORMAT_UNKNOWN:
slouken@1914
   405
        fprintf(stderr, "Unknwon");
slouken@1914
   406
        break;
slouken@1965
   407
    case SDL_PIXELFORMAT_INDEX1LSB:
slouken@1914
   408
        fprintf(stderr, "Index1LSB");
slouken@1914
   409
        break;
slouken@1965
   410
    case SDL_PIXELFORMAT_INDEX1MSB:
slouken@1914
   411
        fprintf(stderr, "Index1MSB");
slouken@1914
   412
        break;
slouken@1965
   413
    case SDL_PIXELFORMAT_INDEX4LSB:
slouken@1914
   414
        fprintf(stderr, "Index4LSB");
slouken@1914
   415
        break;
slouken@1965
   416
    case SDL_PIXELFORMAT_INDEX4MSB:
slouken@1914
   417
        fprintf(stderr, "Index4MSB");
slouken@1914
   418
        break;
slouken@1965
   419
    case SDL_PIXELFORMAT_INDEX8:
slouken@1914
   420
        fprintf(stderr, "Index8");
slouken@1914
   421
        break;
slouken@1965
   422
    case SDL_PIXELFORMAT_RGB332:
slouken@1914
   423
        fprintf(stderr, "RGB332");
slouken@1914
   424
        break;
slouken@1965
   425
    case SDL_PIXELFORMAT_RGB444:
slouken@1914
   426
        fprintf(stderr, "RGB444");
slouken@1914
   427
        break;
slouken@1965
   428
    case SDL_PIXELFORMAT_RGB555:
slouken@1914
   429
        fprintf(stderr, "RGB555");
slouken@1914
   430
        break;
slouken@4621
   431
    case SDL_PIXELFORMAT_BGR555:
slouken@4621
   432
        fprintf(stderr, "BGR555");
slouken@4621
   433
        break;
slouken@1965
   434
    case SDL_PIXELFORMAT_ARGB4444:
slouken@1914
   435
        fprintf(stderr, "ARGB4444");
slouken@1914
   436
        break;
lestat@3184
   437
    case SDL_PIXELFORMAT_ABGR4444:
lestat@3184
   438
        fprintf(stderr, "ABGR4444");
lestat@3184
   439
        break;
slouken@1965
   440
    case SDL_PIXELFORMAT_ARGB1555:
slouken@1914
   441
        fprintf(stderr, "ARGB1555");
slouken@1914
   442
        break;
lestat@3184
   443
    case SDL_PIXELFORMAT_ABGR1555:
lestat@3184
   444
        fprintf(stderr, "ABGR1555");
lestat@3184
   445
        break;
slouken@1965
   446
    case SDL_PIXELFORMAT_RGB565:
slouken@1914
   447
        fprintf(stderr, "RGB565");
slouken@1914
   448
        break;
lestat@3184
   449
    case SDL_PIXELFORMAT_BGR565:
lestat@3184
   450
        fprintf(stderr, "BGR565");
lestat@3184
   451
        break;
slouken@1965
   452
    case SDL_PIXELFORMAT_RGB24:
slouken@1914
   453
        fprintf(stderr, "RGB24");
slouken@1914
   454
        break;
slouken@1965
   455
    case SDL_PIXELFORMAT_BGR24:
slouken@1914
   456
        fprintf(stderr, "BGR24");
slouken@1914
   457
        break;
slouken@1965
   458
    case SDL_PIXELFORMAT_RGB888:
slouken@1914
   459
        fprintf(stderr, "RGB888");
slouken@1914
   460
        break;
slouken@1965
   461
    case SDL_PIXELFORMAT_BGR888:
slouken@1914
   462
        fprintf(stderr, "BGR888");
slouken@1914
   463
        break;
slouken@1965
   464
    case SDL_PIXELFORMAT_ARGB8888:
slouken@1914
   465
        fprintf(stderr, "ARGB8888");
slouken@1914
   466
        break;
slouken@1965
   467
    case SDL_PIXELFORMAT_RGBA8888:
slouken@1914
   468
        fprintf(stderr, "RGBA8888");
slouken@1914
   469
        break;
slouken@1965
   470
    case SDL_PIXELFORMAT_ABGR8888:
slouken@1914
   471
        fprintf(stderr, "ABGR8888");
slouken@1914
   472
        break;
slouken@1965
   473
    case SDL_PIXELFORMAT_BGRA8888:
slouken@1914
   474
        fprintf(stderr, "BGRA8888");
slouken@1914
   475
        break;
slouken@1965
   476
    case SDL_PIXELFORMAT_ARGB2101010:
slouken@1914
   477
        fprintf(stderr, "ARGB2101010");
slouken@1914
   478
        break;
slouken@1965
   479
    case SDL_PIXELFORMAT_YV12:
slouken@1914
   480
        fprintf(stderr, "YV12");
slouken@1914
   481
        break;
slouken@1965
   482
    case SDL_PIXELFORMAT_IYUV:
slouken@1914
   483
        fprintf(stderr, "IYUV");
slouken@1914
   484
        break;
slouken@1965
   485
    case SDL_PIXELFORMAT_YUY2:
slouken@1914
   486
        fprintf(stderr, "YUY2");
slouken@1914
   487
        break;
slouken@1965
   488
    case SDL_PIXELFORMAT_UYVY:
slouken@1914
   489
        fprintf(stderr, "UYVY");
slouken@1914
   490
        break;
slouken@1965
   491
    case SDL_PIXELFORMAT_YVYU:
slouken@1914
   492
        fprintf(stderr, "YVYU");
slouken@1914
   493
        break;
slouken@1914
   494
    default:
slouken@1914
   495
        fprintf(stderr, "0x%8.8x", format);
slouken@1914
   496
        break;
slouken@1914
   497
    }
slouken@1914
   498
}
slouken@1914
   499
slouken@1914
   500
static void
slouken@1914
   501
PrintRenderer(SDL_RendererInfo * info)
slouken@1914
   502
{
slouken@1914
   503
    int i, count;
slouken@1914
   504
slouken@1914
   505
    fprintf(stderr, "  Renderer %s:\n", info->name);
slouken@1914
   506
slouken@1914
   507
    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
slouken@1914
   508
    fprintf(stderr, " (");
slouken@1914
   509
    count = 0;
slouken@1914
   510
    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
slouken@1914
   511
        Uint32 flag = (1 << i);
slouken@1914
   512
        if (info->flags & flag) {
slouken@1914
   513
            if (count > 0) {
slouken@1914
   514
                fprintf(stderr, " | ");
slouken@1914
   515
            }
slouken@1914
   516
            PrintRendererFlag(flag);
slouken@1914
   517
            ++count;
slouken@1914
   518
        }
slouken@1914
   519
    }
slouken@1914
   520
    fprintf(stderr, ")\n");
slouken@1914
   521
slouken@1914
   522
    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
bob@2185
   523
    for (i = 0; i < (int) info->num_texture_formats; ++i) {
slouken@1914
   524
        if (i > 0) {
slouken@1914
   525
            fprintf(stderr, ", ");
slouken@1914
   526
        }
slouken@1914
   527
        PrintPixelFormat(info->texture_formats[i]);
slouken@1914
   528
    }
slouken@1914
   529
    fprintf(stderr, "\n");
slouken@1914
   530
slouken@1914
   531
    if (info->max_texture_width || info->max_texture_height) {
slouken@1914
   532
        fprintf(stderr, "    Max Texture Size: %dx%d\n",
slouken@1914
   533
                info->max_texture_width, info->max_texture_height);
slouken@1914
   534
    }
slouken@1914
   535
}
slouken@1914
   536
slouken@4527
   537
static SDL_Surface *
slouken@4527
   538
LoadIcon(const char *file)
slouken@4527
   539
{
slouken@4527
   540
    SDL_Surface *icon;
slouken@4527
   541
slouken@4527
   542
    /* Load the icon surface */
slouken@4527
   543
    icon = SDL_LoadBMP(file);
slouken@4527
   544
    if (icon == NULL) {
slouken@4527
   545
        fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
slouken@4527
   546
        return (NULL);
slouken@4527
   547
    }
slouken@4527
   548
slouken@6509
   549
    if (icon->format->palette) {
slouken@6509
   550
        /* Set the colorkey */
slouken@6509
   551
        SDL_SetColorKey(icon, 1, *((Uint8 *) icon->pixels));
slouken@4527
   552
    }
slouken@4527
   553
slouken@4527
   554
    return (icon);
slouken@4527
   555
}
slouken@4527
   556
slouken@1914
   557
SDL_bool
slouken@1914
   558
CommonInit(CommonState * state)
slouken@1914
   559
{
slouken@6471
   560
    int i, j, m, n, w, h;
slouken@1914
   561
    SDL_DisplayMode fullscreen_mode;
slouken@1914
   562
slouken@1914
   563
    if (state->flags & SDL_INIT_VIDEO) {
slouken@1914
   564
        if (state->verbose & VERBOSE_VIDEO) {
slouken@1914
   565
            n = SDL_GetNumVideoDrivers();
slouken@1914
   566
            if (n == 0) {
slouken@1914
   567
                fprintf(stderr, "No built-in video drivers\n");
slouken@1914
   568
            } else {
slouken@1914
   569
                fprintf(stderr, "Built-in video drivers:");
slouken@1914
   570
                for (i = 0; i < n; ++i) {
slouken@1914
   571
                    if (i > 0) {
slouken@1914
   572
                        fprintf(stderr, ",");
slouken@1914
   573
                    }
slouken@1914
   574
                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
slouken@1914
   575
                }
slouken@1914
   576
                fprintf(stderr, "\n");
slouken@1914
   577
            }
slouken@1914
   578
        }
slouken@5123
   579
        if (SDL_VideoInit(state->videodriver) < 0) {
slouken@1914
   580
            fprintf(stderr, "Couldn't initialize video driver: %s\n",
slouken@1914
   581
                    SDL_GetError());
slouken@1914
   582
            return SDL_FALSE;
slouken@1914
   583
        }
slouken@1914
   584
        if (state->verbose & VERBOSE_VIDEO) {
slouken@1914
   585
            fprintf(stderr, "Video driver: %s\n",
slouken@1914
   586
                    SDL_GetCurrentVideoDriver());
slouken@1914
   587
        }
slouken@1914
   588
lestat@3408
   589
        /* Upload GL settings */
lestat@3408
   590
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
lestat@3408
   591
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
lestat@3408
   592
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
lestat@3408
   593
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
lestat@3408
   594
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
lestat@3408
   595
        SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
lestat@3408
   596
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
lestat@3408
   597
        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
lestat@3408
   598
        SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
lestat@3408
   599
        SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
lestat@3408
   600
        SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
lestat@3408
   601
        SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
lestat@3408
   602
        SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
lestat@3408
   603
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
lestat@3408
   604
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
slouken@3571
   605
        if (state->gl_accelerated >= 0) {
slouken@3571
   606
            SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
slouken@3571
   607
                                state->gl_accelerated);
slouken@3571
   608
        }
lestat@3408
   609
        SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
slouken@5363
   610
        if (state->gl_major_version) {
slouken@5363
   611
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
slouken@5363
   612
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
slouken@5363
   613
        }
lestat@3408
   614
slouken@1914
   615
        if (state->verbose & VERBOSE_MODES) {
slouken@6505
   616
            SDL_Rect bounds;
slouken@1967
   617
            SDL_DisplayMode mode;
slouken@1914
   618
            int bpp;
slouken@1914
   619
            Uint32 Rmask, Gmask, Bmask, Amask;
slouken@1914
   620
slouken@1914
   621
            n = SDL_GetNumVideoDisplays();
slouken@1914
   622
            fprintf(stderr, "Number of displays: %d\n", n);
slouken@1914
   623
            for (i = 0; i < n; ++i) {
slouken@1914
   624
                fprintf(stderr, "Display %d:\n", i);
slouken@1914
   625
slouken@6505
   626
                SDL_zero(bounds);
slouken@6505
   627
                SDL_GetDisplayBounds(i, &bounds);
slouken@6505
   628
                fprintf(stderr, "Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);
slouken@6505
   629
slouken@5244
   630
                SDL_GetDesktopDisplayMode(i, &mode);
slouken@1967
   631
                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
slouken@1914
   632
                                           &Bmask, &Amask);
slouken@1914
   633
                fprintf(stderr,
lestat@3184
   634
                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
lestat@3184
   635
                        mode.w, mode.h, mode.refresh_rate, bpp,
slouken@4982
   636
                        SDL_GetPixelFormatName(mode.format));
slouken@1914
   637
                if (Rmask || Gmask || Bmask) {
lestat@3184
   638
                    fprintf(stderr, "      Red Mask   = 0x%.8x\n", Rmask);
slouken@1914
   639
                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
lestat@3184
   640
                    fprintf(stderr, "      Blue Mask  = 0x%.8x\n", Bmask);
slouken@1914
   641
                    if (Amask)
slouken@1914
   642
                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
slouken@1914
   643
                }
slouken@1914
   644
slouken@1914
   645
                /* Print available fullscreen video modes */
slouken@5244
   646
                m = SDL_GetNumDisplayModes(i);
slouken@1914
   647
                if (m == 0) {
slouken@1914
   648
                    fprintf(stderr, "No available fullscreen video modes\n");
slouken@1914
   649
                } else {
slouken@1914
   650
                    fprintf(stderr, "  Fullscreen video modes:\n");
slouken@1914
   651
                    for (j = 0; j < m; ++j) {
slouken@5244
   652
                        SDL_GetDisplayMode(i, j, &mode);
slouken@1967
   653
                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
slouken@1914
   654
                                                   &Gmask, &Bmask, &Amask);
slouken@1914
   655
                        fprintf(stderr,
lestat@3184
   656
                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
lestat@3184
   657
                                j, mode.w, mode.h, mode.refresh_rate, bpp,
slouken@4982
   658
                                SDL_GetPixelFormatName(mode.format));
slouken@1914
   659
                        if (Rmask || Gmask || Bmask) {
lestat@3184
   660
                            fprintf(stderr, "        Red Mask   = 0x%.8x\n",
slouken@1914
   661
                                    Rmask);
slouken@1914
   662
                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
slouken@1914
   663
                                    Gmask);
lestat@3184
   664
                            fprintf(stderr, "        Blue Mask  = 0x%.8x\n",
slouken@1914
   665
                                    Bmask);
slouken@1914
   666
                            if (Amask)
slouken@1914
   667
                                fprintf(stderr,
slouken@1914
   668
                                        "        Alpha Mask = 0x%.8x\n",
slouken@1914
   669
                                        Amask);
slouken@1914
   670
                        }
slouken@1914
   671
                    }
slouken@1914
   672
                }
slouken@1914
   673
            }
slouken@1914
   674
        }
slouken@1914
   675
slouken@1914
   676
        if (state->verbose & VERBOSE_RENDER) {
slouken@1914
   677
            SDL_RendererInfo info;
slouken@1914
   678
slouken@1969
   679
            n = SDL_GetNumRenderDrivers();
slouken@1914
   680
            if (n == 0) {
slouken@1914
   681
                fprintf(stderr, "No built-in render drivers\n");
slouken@1914
   682
            } else {
slouken@1923
   683
                fprintf(stderr, "Built-in render drivers:\n");
slouken@1914
   684
                for (i = 0; i < n; ++i) {
slouken@1969
   685
                    SDL_GetRenderDriverInfo(i, &info);
slouken@1914
   686
                    PrintRenderer(&info);
slouken@1914
   687
                }
slouken@1914
   688
            }
slouken@1914
   689
        }
slouken@1914
   690
slouken@3500
   691
        SDL_zero(fullscreen_mode);
slouken@1914
   692
        switch (state->depth) {
slouken@1914
   693
        case 8:
slouken@1965
   694
            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
slouken@1914
   695
            break;
slouken@1914
   696
        case 15:
slouken@1965
   697
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
slouken@1914
   698
            break;
slouken@1914
   699
        case 16:
slouken@1965
   700
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
slouken@1914
   701
            break;
lestat@3184
   702
        case 24:
lestat@3184
   703
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
lestat@3184
   704
            break;
slouken@1914
   705
        default:
slouken@1965
   706
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
slouken@1914
   707
            break;
slouken@1914
   708
        }
slouken@1914
   709
        fullscreen_mode.refresh_rate = state->refresh_rate;
slouken@1914
   710
slouken@1914
   711
        state->windows =
slouken@3685
   712
            (SDL_Window **) SDL_malloc(state->num_windows *
slouken@1914
   713
                                        sizeof(*state->windows));
slouken@5147
   714
        state->renderers =
slouken@5147
   715
            (SDL_Renderer **) SDL_malloc(state->num_windows *
slouken@5147
   716
                                        sizeof(*state->renderers));
slouken@5147
   717
        if (!state->windows || !state->renderers) {
slouken@1914
   718
            fprintf(stderr, "Out of memory!\n");
slouken@1914
   719
            return SDL_FALSE;
slouken@1914
   720
        }
slouken@1914
   721
        for (i = 0; i < state->num_windows; ++i) {
slouken@1914
   722
            char title[1024];
slouken@1914
   723
slouken@1914
   724
            if (state->num_windows > 1) {
slouken@1914
   725
                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
slouken@1914
   726
                             state->window_title, i + 1);
slouken@1914
   727
            } else {
slouken@1914
   728
                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
slouken@1914
   729
            }
slouken@1914
   730
            state->windows[i] =
slouken@1914
   731
                SDL_CreateWindow(title, state->window_x, state->window_y,
slouken@1914
   732
                                 state->window_w, state->window_h,
slouken@1914
   733
                                 state->window_flags);
slouken@1914
   734
            if (!state->windows[i]) {
slouken@1914
   735
                fprintf(stderr, "Couldn't create window: %s\n",
slouken@1914
   736
                        SDL_GetError());
slouken@1914
   737
                return SDL_FALSE;
slouken@1914
   738
            }
slouken@6471
   739
            SDL_GetWindowSize(state->windows[i], &w, &h);
slouken@6503
   740
            if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
slouken@6503
   741
                (w != state->window_w || h != state->window_h)) {
slouken@6471
   742
                printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
slouken@6471
   743
                state->window_w = w;
slouken@6471
   744
                state->window_h = h;
slouken@6471
   745
            }
slouken@3500
   746
            if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
slouken@3500
   747
                fprintf(stderr, "Can't set up fullscreen display mode: %s\n",
slouken@3500
   748
                        SDL_GetError());
slouken@3500
   749
                return SDL_FALSE;
slouken@3500
   750
            }
slouken@4527
   751
slouken@4527
   752
            if (state->window_icon) {
slouken@4527
   753
                SDL_Surface *icon = LoadIcon(state->window_icon);
slouken@4527
   754
                if (icon) {
slouken@4527
   755
                    SDL_SetWindowIcon(state->windows[i], icon);
slouken@4527
   756
                    SDL_FreeSurface(icon);
slouken@4527
   757
                }
slouken@4527
   758
            }
slouken@4527
   759
slouken@3500
   760
            SDL_ShowWindow(state->windows[i]);
slouken@3500
   761
slouken@5147
   762
            state->renderers[i] = NULL;
slouken@5147
   763
slouken@1933
   764
            if (!state->skip_renderer
slouken@1933
   765
                && (state->renderdriver
slouken@1933
   766
                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
slouken@1914
   767
                m = -1;
slouken@1914
   768
                if (state->renderdriver) {
slouken@1914
   769
                    SDL_RendererInfo info;
slouken@1969
   770
                    n = SDL_GetNumRenderDrivers();
slouken@1914
   771
                    for (j = 0; j < n; ++j) {
slouken@1969
   772
                        SDL_GetRenderDriverInfo(j, &info);
slouken@1914
   773
                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
slouken@1914
   774
                            0) {
slouken@1914
   775
                            m = j;
slouken@1914
   776
                            break;
slouken@1914
   777
                        }
slouken@1914
   778
                    }
slouken@1914
   779
                    if (m == n) {
slouken@1914
   780
                        fprintf(stderr,
slouken@1914
   781
                                "Couldn't find render driver named %s",
slouken@1914
   782
                                state->renderdriver);
slouken@1914
   783
                        return SDL_FALSE;
slouken@1914
   784
                    }
slouken@1914
   785
                }
slouken@5147
   786
                state->renderers[i] = SDL_CreateRenderer(state->windows[i],
slouken@5147
   787
                                            m, state->render_flags);
slouken@5147
   788
                if (!state->renderers[i]) {
slouken@1914
   789
                    fprintf(stderr, "Couldn't create renderer: %s\n",
slouken@1914
   790
                            SDL_GetError());
slouken@1914
   791
                    return SDL_FALSE;
slouken@1914
   792
                }
slouken@1923
   793
                if (state->verbose & VERBOSE_RENDER) {
slouken@1923
   794
                    SDL_RendererInfo info;
slouken@1923
   795
slouken@1923
   796
                    fprintf(stderr, "Current renderer:\n");
slouken@5147
   797
                    SDL_GetRendererInfo(state->renderers[i], &info);
slouken@1923
   798
                    PrintRenderer(&info);
slouken@1923
   799
                }
slouken@1914
   800
            }
slouken@1914
   801
        }
slouken@1914
   802
    }
slouken@1914
   803
slouken@1914
   804
    if (state->flags & SDL_INIT_AUDIO) {
slouken@1914
   805
        if (state->verbose & VERBOSE_AUDIO) {
slouken@1914
   806
            n = SDL_GetNumAudioDrivers();
slouken@1914
   807
            if (n == 0) {
slouken@1914
   808
                fprintf(stderr, "No built-in audio drivers\n");
slouken@1914
   809
            } else {
slouken@1914
   810
                fprintf(stderr, "Built-in audio drivers:");
slouken@1914
   811
                for (i = 0; i < n; ++i) {
slouken@1914
   812
                    if (i > 0) {
slouken@1914
   813
                        fprintf(stderr, ",");
slouken@1914
   814
                    }
slouken@1914
   815
                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
slouken@1914
   816
                }
slouken@1914
   817
                fprintf(stderr, "\n");
slouken@1914
   818
            }
slouken@1914
   819
        }
slouken@1914
   820
        if (SDL_AudioInit(state->audiodriver) < 0) {
slouken@1914
   821
            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
slouken@1914
   822
                    SDL_GetError());
slouken@1914
   823
            return SDL_FALSE;
slouken@1914
   824
        }
slouken@1914
   825
        if (state->verbose & VERBOSE_VIDEO) {
slouken@1914
   826
            fprintf(stderr, "Audio driver: %s\n",
slouken@1914
   827
                    SDL_GetCurrentAudioDriver());
slouken@1914
   828
        }
slouken@1914
   829
slouken@1914
   830
        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
slouken@1914
   831
            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
slouken@1914
   832
            return SDL_FALSE;
slouken@1914
   833
        }
slouken@1914
   834
    }
slouken@1914
   835
slouken@1914
   836
    return SDL_TRUE;
slouken@1914
   837
}
slouken@1914
   838
slouken@1914
   839
static void
slouken@1914
   840
PrintEvent(SDL_Event * event)
slouken@1914
   841
{
slouken@5404
   842
    if (event->type == SDL_MOUSEMOTION) {
slouken@5404
   843
        /* Mouse motion is really spammy */
slouken@5406
   844
        //return;
slouken@5404
   845
    }
slouken@5404
   846
slouken@1914
   847
    fprintf(stderr, "SDL EVENT: ");
slouken@1914
   848
    switch (event->type) {
slouken@1914
   849
    case SDL_WINDOWEVENT:
slouken@1914
   850
        switch (event->window.event) {
slouken@1914
   851
        case SDL_WINDOWEVENT_SHOWN:
slouken@1914
   852
            fprintf(stderr, "Window %d shown", event->window.windowID);
slouken@1914
   853
            break;
slouken@1914
   854
        case SDL_WINDOWEVENT_HIDDEN:
slouken@1914
   855
            fprintf(stderr, "Window %d hidden", event->window.windowID);
slouken@1914
   856
            break;
slouken@1914
   857
        case SDL_WINDOWEVENT_EXPOSED:
slouken@1970
   858
            fprintf(stderr, "Window %d exposed", event->window.windowID);
slouken@1914
   859
            break;
slouken@1914
   860
        case SDL_WINDOWEVENT_MOVED:
slouken@1970
   861
            fprintf(stderr, "Window %d moved to %d,%d",
slouken@1914
   862
                    event->window.windowID, event->window.data1,
slouken@1914
   863
                    event->window.data2);
slouken@1914
   864
            break;
slouken@1914
   865
        case SDL_WINDOWEVENT_RESIZED:
slouken@1970
   866
            fprintf(stderr, "Window %d resized to %dx%d",
slouken@1914
   867
                    event->window.windowID, event->window.data1,
slouken@1914
   868
                    event->window.data2);
slouken@1914
   869
            break;
slouken@6508
   870
        case SDL_WINDOWEVENT_SIZE_CHANGED:
slouken@6508
   871
            fprintf(stderr, "Window %d changed size to %dx%d",
slouken@6508
   872
                    event->window.windowID, event->window.data1,
slouken@6508
   873
                    event->window.data2);
slouken@6508
   874
            break;
slouken@1914
   875
        case SDL_WINDOWEVENT_MINIMIZED:
slouken@1914
   876
            fprintf(stderr, "Window %d minimized", event->window.windowID);
slouken@1914
   877
            break;
slouken@1914
   878
        case SDL_WINDOWEVENT_MAXIMIZED:
slouken@1914
   879
            fprintf(stderr, "Window %d maximized", event->window.windowID);
slouken@1914
   880
            break;
slouken@1914
   881
        case SDL_WINDOWEVENT_RESTORED:
slouken@1914
   882
            fprintf(stderr, "Window %d restored", event->window.windowID);
slouken@1914
   883
            break;
slouken@1914
   884
        case SDL_WINDOWEVENT_ENTER:
slouken@1914
   885
            fprintf(stderr, "Mouse entered window %d",
slouken@1914
   886
                    event->window.windowID);
slouken@1914
   887
            break;
slouken@1914
   888
        case SDL_WINDOWEVENT_LEAVE:
slouken@1914
   889
            fprintf(stderr, "Mouse left window %d", event->window.windowID);
slouken@1914
   890
            break;
slouken@1914
   891
        case SDL_WINDOWEVENT_FOCUS_GAINED:
slouken@1914
   892
            fprintf(stderr, "Window %d gained keyboard focus",
slouken@1914
   893
                    event->window.windowID);
slouken@1914
   894
            break;
slouken@1914
   895
        case SDL_WINDOWEVENT_FOCUS_LOST:
slouken@1914
   896
            fprintf(stderr, "Window %d lost keyboard focus",
slouken@1914
   897
                    event->window.windowID);
slouken@1914
   898
            break;
slouken@1933
   899
        case SDL_WINDOWEVENT_CLOSE:
slouken@1933
   900
            fprintf(stderr, "Window %d closed", event->window.windowID);
slouken@1933
   901
            break;
slouken@1914
   902
        default:
slouken@1914
   903
            fprintf(stderr, "Window %d got unknown event %d",
slouken@1914
   904
                    event->window.windowID, event->window.event);
slouken@1914
   905
            break;
slouken@1914
   906
        }
slouken@1914
   907
        break;
slouken@1914
   908
    case SDL_KEYDOWN:
slouken@2268
   909
        fprintf(stderr,
slouken@4465
   910
                "Keyboard: key pressed  in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
slouken@4465
   911
                event->key.windowID,
slouken@2306
   912
                event->key.keysym.scancode,
slouken@2306
   913
                SDL_GetScancodeName(event->key.keysym.scancode),
slouken@2306
   914
                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
slouken@1914
   915
        break;
slouken@1914
   916
    case SDL_KEYUP:
slouken@2268
   917
        fprintf(stderr,
slouken@4465
   918
                "Keyboard: key released in window %d: scancode 0x%08X = %s, keycode 0x%08X = %s",
slouken@4465
   919
                event->key.windowID,
slouken@2306
   920
                event->key.keysym.scancode,
slouken@2306
   921
                SDL_GetScancodeName(event->key.keysym.scancode),
slouken@2306
   922
                event->key.keysym.sym, SDL_GetKeyName(event->key.keysym.sym));
slouken@1914
   923
        break;
slouken@1914
   924
    case SDL_TEXTINPUT:
slouken@4465
   925
        fprintf(stderr, "Keyboard: text input \"%s\" in window %d",
slouken@4465
   926
                event->text.text, event->text.windowID);
slouken@1914
   927
        break;
slouken@1914
   928
    case SDL_MOUSEMOTION:
slouken@4465
   929
        fprintf(stderr, "Mouse: moved to %d,%d (%d,%d) in window %d",
slouken@4465
   930
                event->motion.x, event->motion.y,
slouken@1914
   931
                event->motion.xrel, event->motion.yrel,
slouken@1914
   932
                event->motion.windowID);
slouken@1914
   933
        break;
slouken@1914
   934
    case SDL_MOUSEBUTTONDOWN:
slouken@4465
   935
        fprintf(stderr, "Mouse: button %d pressed at %d,%d in window %d",
slouken@4465
   936
                event->button.button, event->button.x, event->button.y,
slouken@4465
   937
                event->button.windowID);
slouken@1914
   938
        break;
slouken@1914
   939
    case SDL_MOUSEBUTTONUP:
slouken@4465
   940
        fprintf(stderr, "Mouse: button %d released at %d,%d in window %d",
slouken@4465
   941
                event->button.button, event->button.x, event->button.y,
slouken@4465
   942
                event->button.windowID);
slouken@1914
   943
        break;
slouken@1914
   944
    case SDL_MOUSEWHEEL:
slouken@2174
   945
        fprintf(stderr,
slouken@4465
   946
                "Mouse: wheel scrolled %d in x and %d in y in window %d",
slouken@4465
   947
                event->wheel.x, event->wheel.y, event->wheel.windowID);
slouken@1914
   948
        break;
slouken@1914
   949
    case SDL_JOYBALLMOTION:
slouken@1914
   950
        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
slouken@1914
   951
                event->jball.which, event->jball.ball, event->jball.xrel,
slouken@1914
   952
                event->jball.yrel);
slouken@1914
   953
        break;
slouken@1914
   954
    case SDL_JOYHATMOTION:
slouken@1914
   955
        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
slouken@1914
   956
                event->jhat.hat);
slouken@1914
   957
        switch (event->jhat.value) {
slouken@1914
   958
        case SDL_HAT_CENTERED:
slouken@1914
   959
            fprintf(stderr, "CENTER");
slouken@1914
   960
            break;
slouken@1914
   961
        case SDL_HAT_UP:
slouken@1914
   962
            fprintf(stderr, "UP");
slouken@1914
   963
            break;
slouken@1914
   964
        case SDL_HAT_RIGHTUP:
slouken@1914
   965
            fprintf(stderr, "RIGHTUP");
slouken@1914
   966
            break;
slouken@1914
   967
        case SDL_HAT_RIGHT:
slouken@1914
   968
            fprintf(stderr, "RIGHT");
slouken@1914
   969
            break;
slouken@1914
   970
        case SDL_HAT_RIGHTDOWN:
slouken@1914
   971
            fprintf(stderr, "RIGHTDOWN");
slouken@1914
   972
            break;
slouken@1914
   973
        case SDL_HAT_DOWN:
slouken@1914
   974
            fprintf(stderr, "DOWN");
slouken@1914
   975
            break;
slouken@1914
   976
        case SDL_HAT_LEFTDOWN:
slouken@1914
   977
            fprintf(stderr, "LEFTDOWN");
slouken@1914
   978
            break;
slouken@1914
   979
        case SDL_HAT_LEFT:
slouken@1914
   980
            fprintf(stderr, "LEFT");
slouken@1914
   981
            break;
slouken@1914
   982
        case SDL_HAT_LEFTUP:
slouken@1914
   983
            fprintf(stderr, "LEFTUP");
slouken@1914
   984
            break;
slouken@1914
   985
        default:
slouken@1914
   986
            fprintf(stderr, "UNKNOWN");
slouken@1914
   987
            break;
slouken@1914
   988
        }
slouken@1914
   989
        break;
slouken@1914
   990
    case SDL_JOYBUTTONDOWN:
slouken@1914
   991
        fprintf(stderr, "Joystick %d: button %d pressed",
slouken@1914
   992
                event->jbutton.which, event->jbutton.button);
slouken@1914
   993
        break;
slouken@1914
   994
    case SDL_JOYBUTTONUP:
slouken@1914
   995
        fprintf(stderr, "Joystick %d: button %d released",
slouken@1914
   996
                event->jbutton.which, event->jbutton.button);
slouken@1914
   997
        break;
slouken@4503
   998
    case SDL_CLIPBOARDUPDATE:
slouken@4503
   999
        fprintf(stderr, "Clipboard updated");
slouken@4503
  1000
        break;
slouken@1914
  1001
    case SDL_QUIT:
slouken@1914
  1002
        fprintf(stderr, "Quit requested");
slouken@1914
  1003
        break;
slouken@1914
  1004
    case SDL_USEREVENT:
slouken@1914
  1005
        fprintf(stderr, "User event %d", event->user.code);
slouken@1914
  1006
        break;
slouken@1914
  1007
    default:
slouken@1914
  1008
        fprintf(stderr, "Unknown event %d", event->type);
slouken@1914
  1009
        break;
slouken@1914
  1010
    }
slouken@1914
  1011
    fprintf(stderr, "\n");
slouken@1914
  1012
}
slouken@1914
  1013
slouken@5463
  1014
static void
slouken@5463
  1015
ScreenShot(SDL_Renderer *renderer)
slouken@5463
  1016
{
slouken@5463
  1017
    SDL_Rect viewport;
slouken@5463
  1018
    SDL_Surface *surface;
slouken@5463
  1019
slouken@5463
  1020
    if (!renderer) {
slouken@5463
  1021
        return;
slouken@5463
  1022
    }
slouken@5463
  1023
slouken@5463
  1024
    SDL_RenderGetViewport(renderer, &viewport);
slouken@5463
  1025
    surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24,
slouken@5463
  1026
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
slouken@5463
  1027
                    0x00FF0000, 0x0000FF00, 0x000000FF,
slouken@5463
  1028
#else
slouken@5463
  1029
                    0x000000FF, 0x0000FF00, 0x00FF0000,
slouken@5463
  1030
#endif
slouken@5463
  1031
                    0x00000000);
slouken@5463
  1032
    if (!surface) {
slouken@5463
  1033
        fprintf(stderr, "Couldn't create surface: %s\n", SDL_GetError());
slouken@5463
  1034
        return;
slouken@5463
  1035
    }
slouken@5463
  1036
slouken@5463
  1037
    if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
slouken@5463
  1038
                             surface->pixels, surface->pitch) < 0) {
slouken@5463
  1039
        fprintf(stderr, "Couldn't read screen: %s\n", SDL_GetError());
slouken@5463
  1040
        return;
slouken@5463
  1041
    }
slouken@5463
  1042
slouken@5463
  1043
    if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
slouken@5463
  1044
        fprintf(stderr, "Couldn't save screenshot.bmp: %s\n", SDL_GetError());
slouken@5463
  1045
        return;
slouken@5463
  1046
    }
slouken@5463
  1047
}
slouken@5463
  1048
slouken@1914
  1049
void
slouken@1914
  1050
CommonEvent(CommonState * state, SDL_Event * event, int *done)
slouken@1914
  1051
{
slouken@3514
  1052
    int i;
slouken@3514
  1053
slouken@1914
  1054
    if (state->verbose & VERBOSE_EVENT) {
slouken@1914
  1055
        PrintEvent(event);
slouken@1914
  1056
    }
slouken@1914
  1057
slouken@1914
  1058
    switch (event->type) {
slouken@1914
  1059
    case SDL_WINDOWEVENT:
slouken@1914
  1060
        switch (event->window.event) {
slouken@6513
  1061
        case SDL_WINDOWEVENT_SIZE_CHANGED:
slouken@6513
  1062
            {
slouken@6513
  1063
                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
slouken@6513
  1064
                if (window) {
slouken@6513
  1065
                    for (i = 0; i < state->num_windows; ++i) {
slouken@6513
  1066
                        if (window == state->windows[i] &&
slouken@6513
  1067
                            (state->window_flags & SDL_WINDOW_RESIZABLE)) {
slouken@6513
  1068
                            SDL_Rect viewport;
slouken@6513
  1069
slouken@6513
  1070
                            viewport.x = 0;
slouken@6513
  1071
                            viewport.y = 0;
slouken@6513
  1072
                            SDL_GetWindowSize(window, &viewport.w, &viewport.h);
slouken@6513
  1073
                            SDL_RenderSetViewport(state->renderers[i], &viewport);
slouken@6513
  1074
                        }
slouken@6513
  1075
                    }
slouken@6513
  1076
                }
slouken@6513
  1077
            }
slouken@6513
  1078
            break;
slouken@1914
  1079
        case SDL_WINDOWEVENT_CLOSE:
krogoway@5113
  1080
			{
slouken@5463
  1081
                SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
slouken@5463
  1082
                if (window) {
slouken@5463
  1083
					SDL_DestroyWindow(window);
krogoway@5113
  1084
				}
krogoway@5113
  1085
			}
slouken@1914
  1086
            break;
slouken@1914
  1087
        }
slouken@1914
  1088
        break;
slouken@1914
  1089
    case SDL_KEYDOWN:
slouken@1914
  1090
        switch (event->key.keysym.sym) {
slouken@1914
  1091
            /* Add hotkeys here */
slouken@5463
  1092
        case SDLK_PRINTSCREEN: {
slouken@5463
  1093
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@5463
  1094
                if (window) {
slouken@5463
  1095
                    for (i = 0; i < state->num_windows; ++i) {
slouken@5463
  1096
                        if (window == state->windows[i]) {
slouken@5463
  1097
                            ScreenShot(state->renderers[i]);
slouken@5463
  1098
                        }
slouken@5463
  1099
                    }
slouken@5463
  1100
                }
slouken@5463
  1101
            }
slouken@5463
  1102
            break;
slouken@6544
  1103
        case SDLK_EQUALS:
slouken@6544
  1104
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@6544
  1105
                /* Ctrt-+ double the size of the window */
slouken@6543
  1106
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@6543
  1107
                if (window) {
slouken@6543
  1108
                    int w, h;
slouken@6543
  1109
                    SDL_GetWindowSize(window, &w, &h);
slouken@6543
  1110
                    SDL_SetWindowSize(window, w*2, h*2);
slouken@6543
  1111
                }
slouken@6543
  1112
            }
slouken@6543
  1113
            break;
slouken@6544
  1114
        case SDLK_MINUS:
slouken@6544
  1115
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@6544
  1116
                /* Ctrt-- double the size of the window */
slouken@6543
  1117
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@6543
  1118
                if (window) {
slouken@6543
  1119
                    int w, h;
slouken@6543
  1120
                    SDL_GetWindowSize(window, &w, &h);
slouken@6543
  1121
                    SDL_SetWindowSize(window, w/2, h/2);
slouken@6543
  1122
                }
slouken@6543
  1123
            }
slouken@6543
  1124
            break;
slouken@4497
  1125
        case SDLK_c:
slouken@4497
  1126
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@4497
  1127
                /* Ctrl-C copy awesome text! */
slouken@4497
  1128
                SDL_SetClipboardText("SDL rocks!\nYou know it!");
slouken@4497
  1129
                printf("Copied text to clipboard\n");
slouken@4497
  1130
            }
slouken@4497
  1131
            break;
slouken@4497
  1132
        case SDLK_v:
slouken@4497
  1133
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@4497
  1134
                /* Ctrl-V paste awesome text! */
slouken@4497
  1135
                char *text = SDL_GetClipboardText();
slouken@4497
  1136
                if (*text) {
slouken@4497
  1137
                    printf("Clipboard: %s\n", text);
slouken@4497
  1138
                } else {
slouken@4497
  1139
                    printf("Clipboard is empty\n");
slouken@4497
  1140
                }
slouken@4497
  1141
                SDL_free(text);
slouken@4497
  1142
            }
slouken@4497
  1143
            break;
slouken@1965
  1144
        case SDLK_g:
slouken@1965
  1145
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@1965
  1146
                /* Ctrl-G toggle grab */
slouken@5349
  1147
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@5349
  1148
                if (window) {
slouken@5349
  1149
                    SDL_SetWindowGrab(window, !SDL_GetWindowGrab(window));
slouken@5349
  1150
                }
slouken@1965
  1151
            }
slouken@1965
  1152
            break;
slouken@4517
  1153
        case SDLK_m:
slouken@4517
  1154
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@4517
  1155
                /* Ctrl-M maximize */
slouken@5349
  1156
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@5349
  1157
                if (window) {
slouken@5349
  1158
                    Uint32 flags = SDL_GetWindowFlags(window);
slouken@5349
  1159
                    if (flags & SDL_WINDOW_MAXIMIZED) {
slouken@5349
  1160
                        SDL_RestoreWindow(window);
slouken@5349
  1161
                    } else {
slouken@5349
  1162
                        SDL_MaximizeWindow(window);
slouken@4517
  1163
                    }
slouken@4517
  1164
                }
slouken@4517
  1165
            }
slouken@4517
  1166
            break;
slouken@5406
  1167
        case SDLK_r:
slouken@5406
  1168
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@5406
  1169
                /* Ctrl-R toggle mouse relative mode */
slouken@5406
  1170
                SDL_SetRelativeMouseMode(!SDL_GetRelativeMouseMode());
slouken@5406
  1171
            }
slouken@5406
  1172
            break;
slouken@3514
  1173
        case SDLK_z:
slouken@3514
  1174
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@3514
  1175
                /* Ctrl-Z minimize */
slouken@5349
  1176
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@5349
  1177
                if (window) {
slouken@5349
  1178
                    SDL_MinimizeWindow(window);
slouken@5246
  1179
                }
slouken@5246
  1180
            }
slouken@5246
  1181
            break;
slouken@5246
  1182
        case SDLK_RETURN:
slouken@5246
  1183
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@5246
  1184
                /* Ctrl-Enter toggle fullscreen */
slouken@5349
  1185
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@5349
  1186
                if (window) {
slouken@5349
  1187
                    Uint32 flags = SDL_GetWindowFlags(window);
slouken@5349
  1188
                    if (flags & SDL_WINDOW_FULLSCREEN) {
slouken@5349
  1189
                        SDL_SetWindowFullscreen(window, SDL_FALSE);
slouken@5349
  1190
                    } else {
slouken@5349
  1191
                        SDL_SetWindowFullscreen(window, SDL_TRUE);
slouken@5246
  1192
                    }
slouken@3514
  1193
                }
slouken@3514
  1194
            }
slouken@3514
  1195
            break;
icculus@6422
  1196
        case SDLK_b:
icculus@6422
  1197
            if (event->key.keysym.mod & KMOD_CTRL) {
icculus@6422
  1198
                /* Ctrl-B toggle window border */
icculus@6422
  1199
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
icculus@6422
  1200
                if (window) {
icculus@6422
  1201
                    const Uint32 flags = SDL_GetWindowFlags(window);
icculus@6422
  1202
                    const SDL_bool b = ((flags & SDL_WINDOW_BORDERLESS) != 0);
icculus@6422
  1203
                    SDL_SetWindowBordered(window, b);
icculus@6422
  1204
                }
icculus@6422
  1205
            }
icculus@6422
  1206
            break;
slouken@6602
  1207
        case SDLK_1:
slouken@6602
  1208
            if (event->key.keysym.mod & KMOD_CTRL) {
slouken@6602
  1209
                SDL_Window *window = SDL_GetWindowFromID(event->key.windowID);
slouken@6602
  1210
                SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Test Message", "You're awesome!", window);
slouken@6602
  1211
            }
slouken@6602
  1212
            break;
slouken@1914
  1213
        case SDLK_ESCAPE:
slouken@1914
  1214
            *done = 1;
slouken@1914
  1215
            break;
slouken@1914
  1216
        default:
slouken@1914
  1217
            break;
slouken@1914
  1218
        }
slouken@1914
  1219
        break;
slouken@1914
  1220
    case SDL_QUIT:
slouken@1914
  1221
        *done = 1;
slouken@1914
  1222
        break;
slouken@1914
  1223
    }
slouken@1914
  1224
}
slouken@1914
  1225
slouken@1914
  1226
void
slouken@1914
  1227
CommonQuit(CommonState * state)
slouken@1914
  1228
{
slouken@5147
  1229
    int i;
slouken@5147
  1230
slouken@5147
  1231
    if (state->windows) {
slouken@5147
  1232
        SDL_free(state->windows);
slouken@5147
  1233
    }
slouken@5147
  1234
    if (state->renderers) {
slouken@5147
  1235
        for (i = 0; i < state->num_windows; ++i) {
slouken@5147
  1236
            if (state->renderers[i]) {
slouken@5147
  1237
                SDL_DestroyRenderer(state->renderers[i]);
slouken@5147
  1238
            }
slouken@5147
  1239
        }
slouken@5147
  1240
        SDL_free(state->renderers);
slouken@5147
  1241
    }
slouken@1914
  1242
    if (state->flags & SDL_INIT_VIDEO) {
slouken@1914
  1243
        SDL_VideoQuit();
slouken@1914
  1244
    }
slouken@1914
  1245
    if (state->flags & SDL_INIT_AUDIO) {
slouken@1914
  1246
        SDL_AudioQuit();
slouken@1914
  1247
    }
slouken@1914
  1248
    SDL_free(state);
slouken@1914
  1249
}
slouken@3514
  1250
slouken@3514
  1251
/* vi: set ts=4 sw=4 expandtab: */