Added a test program framework for easy initialization.
authorSam Lantinga <slouken@libsdl.org>
Tue, 18 Jul 2006 07:49:51 +0000
changeset 1914051df511279c
parent 1913 83420da906a5
child 1915 a228436a2404
Added a test program framework for easy initialization.
Started work on multi-window OpenGL demo
include/SDL_events.h
test/Makefile.in
test/common.c
test/common.h
test/testgl2.c
test/testsprite2.c
     1.1 --- a/include/SDL_events.h	Mon Jul 17 06:47:33 2006 +0000
     1.2 +++ b/include/SDL_events.h	Tue Jul 18 07:49:51 2006 +0000
     1.3 @@ -119,7 +119,7 @@
     1.4  /**
     1.5   * \struct SDL_WindowEvent
     1.6   *
     1.7 - * \brief Window state change event data
     1.8 + * \brief Window state change event data (event.window.*)
     1.9   */
    1.10  typedef struct SDL_WindowEvent
    1.11  {
    1.12 @@ -133,7 +133,7 @@
    1.13  /**
    1.14   * \struct SDL_KeyboardEvent
    1.15   *
    1.16 - * \brief Keyboard button event structure
    1.17 + * \brief Keyboard button event structure (event.key.*)
    1.18   */
    1.19  typedef struct SDL_KeyboardEvent
    1.20  {
    1.21 @@ -147,7 +147,7 @@
    1.22  /**
    1.23   * \struct SDL_TextInputEvent
    1.24   *
    1.25 - * \brief Keyboard text input event structure
    1.26 + * \brief Keyboard text input event structure (event.text.*)
    1.27   */
    1.28  typedef struct SDL_TextInputEvent
    1.29  {
    1.30 @@ -160,7 +160,7 @@
    1.31  /**
    1.32   * \struct SDL_MouseMotionEvent
    1.33   *
    1.34 - * \brief Mouse motion event structure
    1.35 + * \brief Mouse motion event structure (event.motion.*)
    1.36   */
    1.37  typedef struct SDL_MouseMotionEvent
    1.38  {
    1.39 @@ -177,7 +177,7 @@
    1.40  /**
    1.41   * \struct SDL_MouseButtonEvent
    1.42   *
    1.43 - * \brief Mouse button event structure
    1.44 + * \brief Mouse button event structure (event.button.*)
    1.45   */
    1.46  typedef struct SDL_MouseButtonEvent
    1.47  {
    1.48 @@ -193,20 +193,20 @@
    1.49  /**
    1.50   * \struct SDL_MouseWheelEvent
    1.51   *
    1.52 - * \brief Mouse wheel event structure
    1.53 + * \brief Mouse wheel event structure (event.wheel.*)
    1.54   */
    1.55  typedef struct SDL_MouseWheelEvent
    1.56  {
    1.57      Uint8 type;             /**< SDL_MOUSEWHEEL */
    1.58      Uint8 which;            /**< The mouse device index */
    1.59 -    int motion;                                 /**< The direction and distance scrolled */
    1.60 +    int motion;             /**< The direction and distance scrolled */
    1.61      SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    1.62  } SDL_MouseWheelEvent;
    1.63  
    1.64  /**
    1.65   * \struct SDL_JoyAxisEvent
    1.66   *
    1.67 - * \brief Joystick axis motion event structure
    1.68 + * \brief Joystick axis motion event structure (event.jaxis.*)
    1.69   */
    1.70  typedef struct SDL_JoyAxisEvent
    1.71  {
    1.72 @@ -219,7 +219,7 @@
    1.73  /**
    1.74   * \struct SDL_JoyBallEvent
    1.75   *
    1.76 - * \brief Joystick trackball motion event structure
    1.77 + * \brief Joystick trackball motion event structure (event.jball.*)
    1.78   */
    1.79  typedef struct SDL_JoyBallEvent
    1.80  {
    1.81 @@ -233,7 +233,7 @@
    1.82  /**
    1.83   * \struct SDL_JoyHatEvent
    1.84   *
    1.85 - * \brief Joystick hat position change event structure
    1.86 + * \brief Joystick hat position change event structure (event.jhat.*)
    1.87   */
    1.88  typedef struct SDL_JoyHatEvent
    1.89  {
    1.90 @@ -251,7 +251,7 @@
    1.91  /**
    1.92   * \struct SDL_JoyButtonEvent
    1.93   *
    1.94 - * \brief Joystick button event structure
    1.95 + * \brief Joystick button event structure (event.jbutton.*)
    1.96   */
    1.97  typedef struct SDL_JoyButtonEvent
    1.98  {
    1.99 @@ -274,7 +274,7 @@
   1.100  /**
   1.101   * \struct SDL_UserEvent
   1.102   *
   1.103 - * \brief A user-defined event type
   1.104 + * \brief A user-defined event type (event.user.*)
   1.105   */
   1.106  typedef struct SDL_UserEvent
   1.107  {
   1.108 @@ -287,7 +287,7 @@
   1.109  /**
   1.110   * \struct SDL_SysWMEvent
   1.111   *
   1.112 - * \brief A video driver dependent system event
   1.113 + * \brief A video driver dependent system event (event.syswm.*)
   1.114   *
   1.115   * \note If you want to use this event, you should include SDL_syswm.h
   1.116   */
     2.1 --- a/test/Makefile.in	Mon Jul 17 06:47:33 2006 +0000
     2.2 +++ b/test/Makefile.in	Tue Jul 18 07:49:51 2006 +0000
     2.3 @@ -7,9 +7,12 @@
     2.4  CFLAGS  = @CFLAGS@
     2.5  LIBS	= @LIBS@
     2.6  
     2.7 -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testsprite2$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) testwm2$(EXE) threadwin$(EXE) torturethread$(EXE)
     2.8 +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testgl2$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testsprite2$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) testwm2$(EXE) threadwin$(EXE) torturethread$(EXE)
     2.9  
    2.10 -all: $(TARGETS)
    2.11 +all: Makefile $(TARGETS)
    2.12 +
    2.13 +Makefile: $(srcdir)/Makefile.in
    2.14 +	$(SHELL) config.status $@
    2.15  
    2.16  checkkeys$(EXE): $(srcdir)/checkkeys.c
    2.17  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    2.18 @@ -50,6 +53,9 @@
    2.19  testgl$(EXE): $(srcdir)/testgl.c
    2.20  	$(CC) -o $@ $? $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
    2.21  
    2.22 +testgl2$(EXE): $(srcdir)/testgl2.c
    2.23 +	$(CC) -o $@ $? $(CFLAGS) $(LIBS) @GLLIB@ @MATHLIB@
    2.24 +
    2.25  testhread$(EXE): $(srcdir)/testhread.c
    2.26  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    2.27  
    2.28 @@ -83,8 +89,8 @@
    2.29  testsprite$(EXE): $(srcdir)/testsprite.c
    2.30  	$(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
    2.31  
    2.32 -testsprite2$(EXE): $(srcdir)/testsprite2.c
    2.33 -	$(CC) -o $@ $? $(CFLAGS) $(LIBS) @MATHLIB@
    2.34 +testsprite2$(EXE): $(srcdir)/testsprite2.c $(srcdir)/common.c
    2.35 +	$(CC) -o $@ $(srcdir)/testsprite2.c $(srcdir)/common.c $(CFLAGS) $(LIBS) @MATHLIB@
    2.36  
    2.37  testtimer$(EXE): $(srcdir)/testtimer.c
    2.38  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/common.c	Tue Jul 18 07:49:51 2006 +0000
     3.3 @@ -0,0 +1,927 @@
     3.4 +
     3.5 +/* A simple test program framework */
     3.6 +
     3.7 +#include <stdio.h>
     3.8 +
     3.9 +#include "common.h"
    3.10 +
    3.11 +#define VIDEO_USAGE \
    3.12 +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]"
    3.13 +
    3.14 +#define AUDIO_USAGE \
    3.15 +"[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
    3.16 +
    3.17 +CommonState *
    3.18 +CommonCreateState(char **argv, Uint32 flags)
    3.19 +{
    3.20 +    CommonState *state = SDL_calloc(1, sizeof(*state));
    3.21 +    if (!state) {
    3.22 +        SDL_OutOfMemory();
    3.23 +        return NULL;
    3.24 +    }
    3.25 +
    3.26 +    /* Initialize some defaults */
    3.27 +    state->argv = argv;
    3.28 +    state->flags = flags;
    3.29 +    state->window_title = argv[0];
    3.30 +    state->window_flags = SDL_WINDOW_SHOWN;
    3.31 +    state->window_x = SDL_WINDOWPOS_UNDEFINED;
    3.32 +    state->window_y = SDL_WINDOWPOS_UNDEFINED;
    3.33 +    state->window_w = 640;
    3.34 +    state->window_h = 480;
    3.35 +    state->num_windows = 1;
    3.36 +    state->audiospec.freq = 22050;
    3.37 +    state->audiospec.format = AUDIO_S16;
    3.38 +    state->audiospec.channels = 2;
    3.39 +    state->audiospec.samples = 2048;
    3.40 +    return state;
    3.41 +}
    3.42 +
    3.43 +int
    3.44 +CommonArg(CommonState * state, int index)
    3.45 +{
    3.46 +    char **argv = state->argv;
    3.47 +
    3.48 +    if (SDL_strcasecmp(argv[index], "--video") == 0) {
    3.49 +        ++index;
    3.50 +        if (!argv[index]) {
    3.51 +            return -1;
    3.52 +        }
    3.53 +        state->videodriver = argv[index];
    3.54 +        return 2;
    3.55 +    }
    3.56 +    if (SDL_strcasecmp(argv[index], "--renderer") == 0) {
    3.57 +        ++index;
    3.58 +        if (!argv[index]) {
    3.59 +            return -1;
    3.60 +        }
    3.61 +        if (SDL_strcasecmp(argv[index], "opengl") == 0) {
    3.62 +            state->window_flags |= SDL_WINDOW_OPENGL;
    3.63 +        }
    3.64 +        state->renderdriver = argv[index];
    3.65 +        return 2;
    3.66 +    }
    3.67 +    if (SDL_strcasecmp(argv[index], "--info") == 0) {
    3.68 +        ++index;
    3.69 +        if (!argv[index]) {
    3.70 +            return -1;
    3.71 +        }
    3.72 +        if (SDL_strcasecmp(argv[index], "all") == 0) {
    3.73 +            state->verbose |=
    3.74 +                (VERBOSE_VIDEO | VERBOSE_MODES | VERBOSE_RENDER |
    3.75 +                 VERBOSE_EVENT);
    3.76 +            return 2;
    3.77 +        }
    3.78 +        if (SDL_strcasecmp(argv[index], "video") == 0) {
    3.79 +            state->verbose |= VERBOSE_VIDEO;
    3.80 +            return 2;
    3.81 +        }
    3.82 +        if (SDL_strcasecmp(argv[index], "modes") == 0) {
    3.83 +            state->verbose |= VERBOSE_MODES;
    3.84 +            return 2;
    3.85 +        }
    3.86 +        if (SDL_strcasecmp(argv[index], "render") == 0) {
    3.87 +            state->verbose |= VERBOSE_RENDER;
    3.88 +            return 2;
    3.89 +        }
    3.90 +        if (SDL_strcasecmp(argv[index], "event") == 0) {
    3.91 +            state->verbose |= VERBOSE_EVENT;
    3.92 +            return 2;
    3.93 +        }
    3.94 +        return -1;
    3.95 +    }
    3.96 +    if (SDL_strcasecmp(argv[index], "--display") == 0) {
    3.97 +        ++index;
    3.98 +        if (!argv[index]) {
    3.99 +            return -1;
   3.100 +        }
   3.101 +        state->display = SDL_atoi(argv[index]);
   3.102 +        return 2;
   3.103 +    }
   3.104 +    if (SDL_strcasecmp(argv[index], "--fullscreen") == 0) {
   3.105 +        state->window_flags |= SDL_WINDOW_FULLSCREEN;
   3.106 +        state->num_windows = 1;
   3.107 +        return 1;
   3.108 +    }
   3.109 +    if (SDL_strcasecmp(argv[index], "--windows") == 0) {
   3.110 +        ++index;
   3.111 +        if (!argv[index] || !isdigit(*argv[index])) {
   3.112 +            return -1;
   3.113 +        }
   3.114 +        if (!(state->window_flags & SDL_WINDOW_FULLSCREEN)) {
   3.115 +            state->num_windows = SDL_atoi(argv[index]);
   3.116 +        }
   3.117 +        return 2;
   3.118 +    }
   3.119 +    if (SDL_strcasecmp(argv[index], "--title") == 0) {
   3.120 +        ++index;
   3.121 +        if (!argv[index]) {
   3.122 +            return -1;
   3.123 +        }
   3.124 +        state->window_title = argv[index];
   3.125 +        return 2;
   3.126 +    }
   3.127 +    if (SDL_strcasecmp(argv[index], "--center") == 0) {
   3.128 +        state->window_x = SDL_WINDOWPOS_CENTERED;
   3.129 +        state->window_y = SDL_WINDOWPOS_CENTERED;
   3.130 +        return 1;
   3.131 +    }
   3.132 +    if (SDL_strcasecmp(argv[index], "--position") == 0) {
   3.133 +        char *x, *y;
   3.134 +        ++index;
   3.135 +        if (!argv[index]) {
   3.136 +            return -1;
   3.137 +        }
   3.138 +        x = argv[index];
   3.139 +        y = argv[index];
   3.140 +        while (*y && *y != ',') {
   3.141 +            ++y;
   3.142 +        }
   3.143 +        if (!*y) {
   3.144 +            return -1;
   3.145 +        }
   3.146 +        *y++ = '\0';
   3.147 +        state->window_x = SDL_atoi(x);
   3.148 +        state->window_y = SDL_atoi(y);
   3.149 +        return 2;
   3.150 +    }
   3.151 +    if (SDL_strcasecmp(argv[index], "--geometry") == 0) {
   3.152 +        char *w, *h;
   3.153 +        ++index;
   3.154 +        if (!argv[index]) {
   3.155 +            return -1;
   3.156 +        }
   3.157 +        w = argv[index];
   3.158 +        h = argv[index];
   3.159 +        while (*h && *h != 'x') {
   3.160 +            ++h;
   3.161 +        }
   3.162 +        if (!*h) {
   3.163 +            return -1;
   3.164 +        }
   3.165 +        *h++ = '\0';
   3.166 +        state->window_w = SDL_atoi(w);
   3.167 +        state->window_h = SDL_atoi(h);
   3.168 +        return 2;
   3.169 +    }
   3.170 +    if (SDL_strcasecmp(argv[index], "--refresh") == 0) {
   3.171 +        ++index;
   3.172 +        if (!argv[index]) {
   3.173 +            return -1;
   3.174 +        }
   3.175 +        state->refresh_rate = SDL_atoi(argv[index]);
   3.176 +        return 2;
   3.177 +    }
   3.178 +    if (SDL_strcasecmp(argv[index], "--vsync") == 0) {
   3.179 +        state->render_flags |= SDL_Renderer_PresentVSync;
   3.180 +        return 1;
   3.181 +    }
   3.182 +    if (SDL_strcasecmp(argv[index], "--noframe") == 0) {
   3.183 +        state->window_flags |= SDL_WINDOW_BORDERLESS;
   3.184 +        return 1;
   3.185 +    }
   3.186 +    if (SDL_strcasecmp(argv[index], "--resize") == 0) {
   3.187 +        state->window_flags |= SDL_WINDOW_RESIZABLE;
   3.188 +        return 1;
   3.189 +    }
   3.190 +    if (SDL_strcasecmp(argv[index], "--minimize") == 0) {
   3.191 +        state->window_flags |= SDL_WINDOW_MINIMIZED;
   3.192 +        return 1;
   3.193 +    }
   3.194 +    if (SDL_strcasecmp(argv[index], "--maximize") == 0) {
   3.195 +        state->window_flags |= SDL_WINDOW_MAXIMIZED;
   3.196 +        return 1;
   3.197 +    }
   3.198 +    if (SDL_strcasecmp(argv[index], "--grab") == 0) {
   3.199 +        state->window_flags |= SDL_WINDOW_INPUT_GRABBED;
   3.200 +        return 1;
   3.201 +    }
   3.202 +    if (SDL_strcasecmp(argv[index], "--rate") == 0) {
   3.203 +        ++index;
   3.204 +        if (!argv[index]) {
   3.205 +            return -1;
   3.206 +        }
   3.207 +        state->audiospec.freq = SDL_atoi(argv[index]);
   3.208 +        return 2;
   3.209 +    }
   3.210 +    if (SDL_strcasecmp(argv[index], "--format") == 0) {
   3.211 +        ++index;
   3.212 +        if (!argv[index]) {
   3.213 +            return -1;
   3.214 +        }
   3.215 +        if (SDL_strcasecmp(argv[index], "U8") == 0) {
   3.216 +            state->audiospec.format = AUDIO_U8;
   3.217 +            return 2;
   3.218 +        }
   3.219 +        if (SDL_strcasecmp(argv[index], "S8") == 0) {
   3.220 +            state->audiospec.format = AUDIO_S8;
   3.221 +            return 2;
   3.222 +        }
   3.223 +        if (SDL_strcasecmp(argv[index], "U16") == 0) {
   3.224 +            state->audiospec.format = AUDIO_U16;
   3.225 +            return 2;
   3.226 +        }
   3.227 +        if (SDL_strcasecmp(argv[index], "U16LE") == 0) {
   3.228 +            state->audiospec.format = AUDIO_U16LSB;
   3.229 +            return 2;
   3.230 +        }
   3.231 +        if (SDL_strcasecmp(argv[index], "U16BE") == 0) {
   3.232 +            state->audiospec.format = AUDIO_U16MSB;
   3.233 +            return 2;
   3.234 +        }
   3.235 +        if (SDL_strcasecmp(argv[index], "S16") == 0) {
   3.236 +            state->audiospec.format = AUDIO_S16;
   3.237 +            return 2;
   3.238 +        }
   3.239 +        if (SDL_strcasecmp(argv[index], "S16LE") == 0) {
   3.240 +            state->audiospec.format = AUDIO_S16LSB;
   3.241 +            return 2;
   3.242 +        }
   3.243 +        if (SDL_strcasecmp(argv[index], "S16BE") == 0) {
   3.244 +            state->audiospec.format = AUDIO_S16MSB;
   3.245 +            return 2;
   3.246 +        }
   3.247 +        return -1;
   3.248 +    }
   3.249 +    if (SDL_strcasecmp(argv[index], "--channels") == 0) {
   3.250 +        ++index;
   3.251 +        if (!argv[index]) {
   3.252 +            return -1;
   3.253 +        }
   3.254 +        state->audiospec.channels = SDL_atoi(argv[index]);
   3.255 +        return 2;
   3.256 +    }
   3.257 +    if (SDL_strcasecmp(argv[index], "--samples") == 0) {
   3.258 +        ++index;
   3.259 +        if (!argv[index]) {
   3.260 +            return -1;
   3.261 +        }
   3.262 +        state->audiospec.samples = SDL_atoi(argv[index]);
   3.263 +        return 2;
   3.264 +    }
   3.265 +    if ((SDL_strcasecmp(argv[index], "-h") == 0)
   3.266 +        || (SDL_strcasecmp(argv[index], "--help") == 0)) {
   3.267 +        /* Print the usage message */
   3.268 +        return -1;
   3.269 +    }
   3.270 +    return 0;
   3.271 +}
   3.272 +
   3.273 +const char *
   3.274 +CommonUsage(CommonState * state)
   3.275 +{
   3.276 +    switch (state->flags & (SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
   3.277 +    case SDL_INIT_VIDEO:
   3.278 +        return VIDEO_USAGE;
   3.279 +    case SDL_INIT_AUDIO:
   3.280 +        return AUDIO_USAGE;
   3.281 +    case (SDL_INIT_VIDEO | SDL_INIT_AUDIO):
   3.282 +        return VIDEO_USAGE " " AUDIO_USAGE;
   3.283 +    default:
   3.284 +        return "";
   3.285 +    }
   3.286 +}
   3.287 +
   3.288 +static void
   3.289 +PrintRendererFlag(Uint32 flag)
   3.290 +{
   3.291 +    switch (flag) {
   3.292 +    case SDL_Renderer_SingleBuffer:
   3.293 +        fprintf(stderr, "SingleBuffer");
   3.294 +        break;
   3.295 +    case SDL_Renderer_PresentCopy:
   3.296 +        fprintf(stderr, "PresentCopy");
   3.297 +        break;
   3.298 +    case SDL_Renderer_PresentFlip2:
   3.299 +        fprintf(stderr, "PresentFlip2");
   3.300 +        break;
   3.301 +    case SDL_Renderer_PresentFlip3:
   3.302 +        fprintf(stderr, "PresentFlip3");
   3.303 +        break;
   3.304 +    case SDL_Renderer_PresentDiscard:
   3.305 +        fprintf(stderr, "PresentDiscard");
   3.306 +        break;
   3.307 +    case SDL_Renderer_PresentVSync:
   3.308 +        fprintf(stderr, "PresentVSync");
   3.309 +        break;
   3.310 +    default:
   3.311 +        fprintf(stderr, "0x%8.8x", flag);
   3.312 +        break;
   3.313 +    }
   3.314 +}
   3.315 +
   3.316 +static void
   3.317 +PrintBlendMode(Uint32 flag)
   3.318 +{
   3.319 +    switch (flag) {
   3.320 +    case SDL_TextureBlendMode_None:
   3.321 +        fprintf(stderr, "None");
   3.322 +        break;
   3.323 +    case SDL_TextureBlendMode_Mask:
   3.324 +        fprintf(stderr, "Mask");
   3.325 +        break;
   3.326 +    case SDL_TextureBlendMode_Blend:
   3.327 +        fprintf(stderr, "Blend");
   3.328 +        break;
   3.329 +    case SDL_TextureBlendMode_Add:
   3.330 +        fprintf(stderr, "Add");
   3.331 +        break;
   3.332 +    case SDL_TextureBlendMode_Mod:
   3.333 +        fprintf(stderr, "Mod");
   3.334 +        break;
   3.335 +    default:
   3.336 +        fprintf(stderr, "0x%8.8x", flag);
   3.337 +        break;
   3.338 +    }
   3.339 +}
   3.340 +
   3.341 +static void
   3.342 +PrintScaleMode(Uint32 flag)
   3.343 +{
   3.344 +    switch (flag) {
   3.345 +    case SDL_TextureScaleMode_None:
   3.346 +        fprintf(stderr, "None");
   3.347 +        break;
   3.348 +    case SDL_TextureScaleMode_Fast:
   3.349 +        fprintf(stderr, "Fast");
   3.350 +        break;
   3.351 +    case SDL_TextureScaleMode_Slow:
   3.352 +        fprintf(stderr, "Slow");
   3.353 +        break;
   3.354 +    case SDL_TextureScaleMode_Best:
   3.355 +        fprintf(stderr, "Best");
   3.356 +        break;
   3.357 +    default:
   3.358 +        fprintf(stderr, "0x%8.8x", flag);
   3.359 +        break;
   3.360 +    }
   3.361 +}
   3.362 +
   3.363 +static void
   3.364 +PrintPixelFormat(Uint32 format)
   3.365 +{
   3.366 +    switch (format) {
   3.367 +    case SDL_PixelFormat_Unknown:
   3.368 +        fprintf(stderr, "Unknwon");
   3.369 +        break;
   3.370 +    case SDL_PixelFormat_Index1LSB:
   3.371 +        fprintf(stderr, "Index1LSB");
   3.372 +        break;
   3.373 +    case SDL_PixelFormat_Index1MSB:
   3.374 +        fprintf(stderr, "Index1MSB");
   3.375 +        break;
   3.376 +    case SDL_PixelFormat_Index4LSB:
   3.377 +        fprintf(stderr, "Index4LSB");
   3.378 +        break;
   3.379 +    case SDL_PixelFormat_Index4MSB:
   3.380 +        fprintf(stderr, "Index4MSB");
   3.381 +        break;
   3.382 +    case SDL_PixelFormat_Index8:
   3.383 +        fprintf(stderr, "Index8");
   3.384 +        break;
   3.385 +    case SDL_PixelFormat_RGB332:
   3.386 +        fprintf(stderr, "RGB332");
   3.387 +        break;
   3.388 +    case SDL_PixelFormat_RGB444:
   3.389 +        fprintf(stderr, "RGB444");
   3.390 +        break;
   3.391 +    case SDL_PixelFormat_RGB555:
   3.392 +        fprintf(stderr, "RGB555");
   3.393 +        break;
   3.394 +    case SDL_PixelFormat_ARGB4444:
   3.395 +        fprintf(stderr, "ARGB4444");
   3.396 +        break;
   3.397 +    case SDL_PixelFormat_ARGB1555:
   3.398 +        fprintf(stderr, "ARGB1555");
   3.399 +        break;
   3.400 +    case SDL_PixelFormat_RGB565:
   3.401 +        fprintf(stderr, "RGB565");
   3.402 +        break;
   3.403 +    case SDL_PixelFormat_RGB24:
   3.404 +        fprintf(stderr, "RGB24");
   3.405 +        break;
   3.406 +    case SDL_PixelFormat_BGR24:
   3.407 +        fprintf(stderr, "BGR24");
   3.408 +        break;
   3.409 +    case SDL_PixelFormat_RGB888:
   3.410 +        fprintf(stderr, "RGB888");
   3.411 +        break;
   3.412 +    case SDL_PixelFormat_BGR888:
   3.413 +        fprintf(stderr, "BGR888");
   3.414 +        break;
   3.415 +    case SDL_PixelFormat_ARGB8888:
   3.416 +        fprintf(stderr, "ARGB8888");
   3.417 +        break;
   3.418 +    case SDL_PixelFormat_RGBA8888:
   3.419 +        fprintf(stderr, "RGBA8888");
   3.420 +        break;
   3.421 +    case SDL_PixelFormat_ABGR8888:
   3.422 +        fprintf(stderr, "ABGR8888");
   3.423 +        break;
   3.424 +    case SDL_PixelFormat_BGRA8888:
   3.425 +        fprintf(stderr, "BGRA8888");
   3.426 +        break;
   3.427 +    case SDL_PixelFormat_ARGB2101010:
   3.428 +        fprintf(stderr, "ARGB2101010");
   3.429 +        break;
   3.430 +    case SDL_PixelFormat_YV12:
   3.431 +        fprintf(stderr, "YV12");
   3.432 +        break;
   3.433 +    case SDL_PixelFormat_IYUV:
   3.434 +        fprintf(stderr, "IYUV");
   3.435 +        break;
   3.436 +    case SDL_PixelFormat_YUY2:
   3.437 +        fprintf(stderr, "YUY2");
   3.438 +        break;
   3.439 +    case SDL_PixelFormat_UYVY:
   3.440 +        fprintf(stderr, "UYVY");
   3.441 +        break;
   3.442 +    case SDL_PixelFormat_YVYU:
   3.443 +        fprintf(stderr, "YVYU");
   3.444 +        break;
   3.445 +    default:
   3.446 +        fprintf(stderr, "0x%8.8x", format);
   3.447 +        break;
   3.448 +    }
   3.449 +}
   3.450 +
   3.451 +static void
   3.452 +PrintRenderer(SDL_RendererInfo * info)
   3.453 +{
   3.454 +    int i, count;
   3.455 +
   3.456 +    fprintf(stderr, "  Renderer %s:\n", info->name);
   3.457 +
   3.458 +    fprintf(stderr, "    Flags: 0x%8.8X", info->flags);
   3.459 +    fprintf(stderr, " (");
   3.460 +    count = 0;
   3.461 +    for (i = 0; i < sizeof(info->flags) * 8; ++i) {
   3.462 +        Uint32 flag = (1 << i);
   3.463 +        if (info->flags & flag) {
   3.464 +            if (count > 0) {
   3.465 +                fprintf(stderr, " | ");
   3.466 +            }
   3.467 +            PrintRendererFlag(flag);
   3.468 +            ++count;
   3.469 +        }
   3.470 +    }
   3.471 +    fprintf(stderr, ")\n");
   3.472 +
   3.473 +    fprintf(stderr, "    Blend: 0x%8.8X", info->blend_modes);
   3.474 +    fprintf(stderr, " (");
   3.475 +    count = 0;
   3.476 +    for (i = 0; i < sizeof(info->blend_modes) * 8; ++i) {
   3.477 +        Uint32 flag = (1 << i);
   3.478 +        if (info->blend_modes & flag) {
   3.479 +            if (count > 0) {
   3.480 +                fprintf(stderr, " | ");
   3.481 +            }
   3.482 +            PrintBlendMode(flag);
   3.483 +            ++count;
   3.484 +        }
   3.485 +    }
   3.486 +    fprintf(stderr, ")\n");
   3.487 +
   3.488 +    fprintf(stderr, "    Scale: 0x%8.8X", info->scale_modes);
   3.489 +    fprintf(stderr, " (");
   3.490 +    count = 0;
   3.491 +    for (i = 0; i < sizeof(info->scale_modes) * 8; ++i) {
   3.492 +        Uint32 flag = (1 << i);
   3.493 +        if (info->scale_modes & flag) {
   3.494 +            if (count > 0) {
   3.495 +                fprintf(stderr, " | ");
   3.496 +            }
   3.497 +            PrintScaleMode(flag);
   3.498 +            ++count;
   3.499 +        }
   3.500 +    }
   3.501 +    fprintf(stderr, ")\n");
   3.502 +
   3.503 +    fprintf(stderr, "    Texture formats (%d): ", info->num_texture_formats);
   3.504 +    for (i = 0; i < info->num_texture_formats; ++i) {
   3.505 +        if (i > 0) {
   3.506 +            fprintf(stderr, ", ");
   3.507 +        }
   3.508 +        PrintPixelFormat(info->texture_formats[i]);
   3.509 +    }
   3.510 +    fprintf(stderr, "\n");
   3.511 +
   3.512 +    if (info->max_texture_width || info->max_texture_height) {
   3.513 +        fprintf(stderr, "    Max Texture Size: %dx%d\n",
   3.514 +                info->max_texture_width, info->max_texture_height);
   3.515 +    }
   3.516 +}
   3.517 +
   3.518 +SDL_bool
   3.519 +CommonInit(CommonState * state)
   3.520 +{
   3.521 +    int i, j, m, n;
   3.522 +    SDL_DisplayMode fullscreen_mode;
   3.523 +
   3.524 +    if (state->flags & SDL_INIT_VIDEO) {
   3.525 +        if (state->verbose & VERBOSE_VIDEO) {
   3.526 +            n = SDL_GetNumVideoDrivers();
   3.527 +            if (n == 0) {
   3.528 +                fprintf(stderr, "No built-in video drivers\n");
   3.529 +            } else {
   3.530 +                fprintf(stderr, "Built-in video drivers:");
   3.531 +                for (i = 0; i < n; ++i) {
   3.532 +                    if (i > 0) {
   3.533 +                        fprintf(stderr, ",");
   3.534 +                    }
   3.535 +                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
   3.536 +                }
   3.537 +                fprintf(stderr, "\n");
   3.538 +            }
   3.539 +        }
   3.540 +        if (SDL_VideoInit(state->videodriver, 0) < 0) {
   3.541 +            fprintf(stderr, "Couldn't initialize video driver: %s\n",
   3.542 +                    SDL_GetError());
   3.543 +            return SDL_FALSE;
   3.544 +        }
   3.545 +        if (state->verbose & VERBOSE_VIDEO) {
   3.546 +            fprintf(stderr, "Video driver: %s\n",
   3.547 +                    SDL_GetCurrentVideoDriver());
   3.548 +        }
   3.549 +
   3.550 +        if (state->verbose & VERBOSE_MODES) {
   3.551 +            const SDL_DisplayMode *mode;
   3.552 +            int bpp;
   3.553 +            Uint32 Rmask, Gmask, Bmask, Amask;
   3.554 +
   3.555 +            n = SDL_GetNumVideoDisplays();
   3.556 +            fprintf(stderr, "Number of displays: %d\n", n);
   3.557 +            for (i = 0; i < n; ++i) {
   3.558 +                fprintf(stderr, "Display %d:\n", i);
   3.559 +                SDL_SelectVideoDisplay(i);
   3.560 +
   3.561 +                mode = SDL_GetDesktopDisplayMode();
   3.562 +                SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask,
   3.563 +                                           &Bmask, &Amask);
   3.564 +                fprintf(stderr,
   3.565 +                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel\n",
   3.566 +                        mode->w, mode->h, mode->refresh_rate, bpp);
   3.567 +                if (Rmask || Gmask || Bmask) {
   3.568 +                    fprintf(stderr, "      Red Mask = 0x%.8x\n", Rmask);
   3.569 +                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
   3.570 +                    fprintf(stderr, "      Blue Mask = 0x%.8x\n", Bmask);
   3.571 +                    if (Amask)
   3.572 +                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
   3.573 +                }
   3.574 +
   3.575 +                /* Print available fullscreen video modes */
   3.576 +                m = SDL_GetNumDisplayModes();
   3.577 +                if (m == 0) {
   3.578 +                    fprintf(stderr, "No available fullscreen video modes\n");
   3.579 +                } else {
   3.580 +                    fprintf(stderr, "  Fullscreen video modes:\n");
   3.581 +                    for (j = 0; j < m; ++j) {
   3.582 +                        mode = SDL_GetDisplayMode(j);
   3.583 +                        SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
   3.584 +                                                   &Gmask, &Bmask, &Amask);
   3.585 +                        fprintf(stderr,
   3.586 +                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n",
   3.587 +                                j, mode->w, mode->h, mode->refresh_rate, bpp);
   3.588 +                        if (Rmask || Gmask || Bmask) {
   3.589 +                            fprintf(stderr, "        Red Mask = 0x%.8x\n",
   3.590 +                                    Rmask);
   3.591 +                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
   3.592 +                                    Gmask);
   3.593 +                            fprintf(stderr, "        Blue Mask = 0x%.8x\n",
   3.594 +                                    Bmask);
   3.595 +                            if (Amask)
   3.596 +                                fprintf(stderr,
   3.597 +                                        "        Alpha Mask = 0x%.8x\n",
   3.598 +                                        Amask);
   3.599 +                        }
   3.600 +                    }
   3.601 +                }
   3.602 +            }
   3.603 +        }
   3.604 +
   3.605 +        SDL_SelectVideoDisplay(state->display);
   3.606 +        if (state->verbose & VERBOSE_RENDER) {
   3.607 +            SDL_RendererInfo info;
   3.608 +
   3.609 +            n = SDL_GetNumRenderers();
   3.610 +            if (n == 0) {
   3.611 +                fprintf(stderr, "No built-in render drivers\n");
   3.612 +            } else {
   3.613 +                fprintf(stderr, "Built-in render video drivers:\n");
   3.614 +                for (i = 0; i < n; ++i) {
   3.615 +                    SDL_GetRendererInfo(i, &info);
   3.616 +                    PrintRenderer(&info);
   3.617 +                }
   3.618 +            }
   3.619 +        }
   3.620 +
   3.621 +        switch (state->depth) {
   3.622 +        case 8:
   3.623 +            fullscreen_mode.format = SDL_PixelFormat_Index8;
   3.624 +            break;
   3.625 +        case 15:
   3.626 +            fullscreen_mode.format = SDL_PixelFormat_RGB555;
   3.627 +            break;
   3.628 +        case 16:
   3.629 +            fullscreen_mode.format = SDL_PixelFormat_RGB565;
   3.630 +            break;
   3.631 +        default:
   3.632 +            fullscreen_mode.format = SDL_PixelFormat_RGB888;
   3.633 +            break;
   3.634 +        }
   3.635 +        fullscreen_mode.w = state->window_w;
   3.636 +        fullscreen_mode.h = state->window_h;
   3.637 +        fullscreen_mode.refresh_rate = state->refresh_rate;
   3.638 +        SDL_SetFullscreenDisplayMode(&fullscreen_mode);
   3.639 +
   3.640 +        state->windows =
   3.641 +            (SDL_WindowID *) SDL_malloc(state->num_windows *
   3.642 +                                        sizeof(*state->windows));
   3.643 +        if (!state->windows) {
   3.644 +            fprintf(stderr, "Out of memory!\n");
   3.645 +            return SDL_FALSE;
   3.646 +        }
   3.647 +        for (i = 0; i < state->num_windows; ++i) {
   3.648 +            char title[1024];
   3.649 +
   3.650 +            if (state->num_windows > 1) {
   3.651 +                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
   3.652 +                             state->window_title, i + 1);
   3.653 +            } else {
   3.654 +                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
   3.655 +            }
   3.656 +            state->windows[i] =
   3.657 +                SDL_CreateWindow(title, state->window_x, state->window_y,
   3.658 +                                 state->window_w, state->window_h,
   3.659 +                                 state->window_flags);
   3.660 +            if (!state->windows[i]) {
   3.661 +                fprintf(stderr, "Couldn't create window: %s\n",
   3.662 +                        SDL_GetError());
   3.663 +                return SDL_FALSE;
   3.664 +            }
   3.665 +
   3.666 +            if (state->renderdriver
   3.667 +                || !(state->window_flags & SDL_WINDOW_OPENGL)) {
   3.668 +                m = -1;
   3.669 +                if (state->renderdriver) {
   3.670 +                    SDL_RendererInfo info;
   3.671 +                    n = SDL_GetNumRenderers();
   3.672 +                    for (j = 0; j < n; ++j) {
   3.673 +                        SDL_GetRendererInfo(j, &info);
   3.674 +                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
   3.675 +                            0) {
   3.676 +                            m = j;
   3.677 +                            break;
   3.678 +                        }
   3.679 +                    }
   3.680 +                    if (m == n) {
   3.681 +                        fprintf(stderr,
   3.682 +                                "Couldn't find render driver named %s",
   3.683 +                                state->renderdriver);
   3.684 +                        return SDL_FALSE;
   3.685 +                    }
   3.686 +                }
   3.687 +                if (SDL_CreateRenderer
   3.688 +                    (state->windows[i], m, state->render_flags) < 0) {
   3.689 +                    fprintf(stderr, "Couldn't create renderer: %s\n",
   3.690 +                            SDL_GetError());
   3.691 +                    return SDL_FALSE;
   3.692 +                }
   3.693 +            }
   3.694 +        }
   3.695 +        SDL_SelectRenderer(state->windows[0]);
   3.696 +    }
   3.697 +
   3.698 +    if (state->flags & SDL_INIT_AUDIO) {
   3.699 +        if (state->verbose & VERBOSE_AUDIO) {
   3.700 +            n = SDL_GetNumAudioDrivers();
   3.701 +            if (n == 0) {
   3.702 +                fprintf(stderr, "No built-in audio drivers\n");
   3.703 +            } else {
   3.704 +                fprintf(stderr, "Built-in audio drivers:");
   3.705 +                for (i = 0; i < n; ++i) {
   3.706 +                    if (i > 0) {
   3.707 +                        fprintf(stderr, ",");
   3.708 +                    }
   3.709 +                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
   3.710 +                }
   3.711 +                fprintf(stderr, "\n");
   3.712 +            }
   3.713 +        }
   3.714 +        if (SDL_AudioInit(state->audiodriver) < 0) {
   3.715 +            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
   3.716 +                    SDL_GetError());
   3.717 +            return SDL_FALSE;
   3.718 +        }
   3.719 +        if (state->verbose & VERBOSE_VIDEO) {
   3.720 +            fprintf(stderr, "Audio driver: %s\n",
   3.721 +                    SDL_GetCurrentAudioDriver());
   3.722 +        }
   3.723 +
   3.724 +        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
   3.725 +            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
   3.726 +            return SDL_FALSE;
   3.727 +        }
   3.728 +    }
   3.729 +
   3.730 +    return SDL_TRUE;
   3.731 +}
   3.732 +
   3.733 +static void
   3.734 +PrintEvent(SDL_Event * event)
   3.735 +{
   3.736 +    fprintf(stderr, "SDL EVENT: ");
   3.737 +    switch (event->type) {
   3.738 +    case SDL_WINDOWEVENT:
   3.739 +        switch (event->window.event) {
   3.740 +        case SDL_WINDOWEVENT_SHOWN:
   3.741 +            fprintf(stderr, "Window %d shown", event->window.windowID);
   3.742 +            break;
   3.743 +        case SDL_WINDOWEVENT_HIDDEN:
   3.744 +            fprintf(stderr, "Window %d hidden", event->window.windowID);
   3.745 +            break;
   3.746 +        case SDL_WINDOWEVENT_EXPOSED:
   3.747 +            fprintf(stderr, "Window %d exposed: %d", event->window.windowID);
   3.748 +            break;
   3.749 +        case SDL_WINDOWEVENT_MOVED:
   3.750 +            fprintf(stderr, "Window %d moved to %d,%d: %d",
   3.751 +                    event->window.windowID, event->window.data1,
   3.752 +                    event->window.data2);
   3.753 +            break;
   3.754 +        case SDL_WINDOWEVENT_RESIZED:
   3.755 +            fprintf(stderr, "Window %d resized to %dx%d: %d",
   3.756 +                    event->window.windowID, event->window.data1,
   3.757 +                    event->window.data2);
   3.758 +            break;
   3.759 +        case SDL_WINDOWEVENT_MINIMIZED:
   3.760 +            fprintf(stderr, "Window %d minimized", event->window.windowID);
   3.761 +            break;
   3.762 +        case SDL_WINDOWEVENT_MAXIMIZED:
   3.763 +            fprintf(stderr, "Window %d maximized", event->window.windowID);
   3.764 +            break;
   3.765 +        case SDL_WINDOWEVENT_RESTORED:
   3.766 +            fprintf(stderr, "Window %d restored", event->window.windowID);
   3.767 +            break;
   3.768 +        case SDL_WINDOWEVENT_ENTER:
   3.769 +            fprintf(stderr, "Mouse entered window %d",
   3.770 +                    event->window.windowID);
   3.771 +            break;
   3.772 +        case SDL_WINDOWEVENT_LEAVE:
   3.773 +            fprintf(stderr, "Mouse left window %d", event->window.windowID);
   3.774 +            break;
   3.775 +        case SDL_WINDOWEVENT_FOCUS_GAINED:
   3.776 +            fprintf(stderr, "Window %d gained keyboard focus",
   3.777 +                    event->window.windowID);
   3.778 +            break;
   3.779 +        case SDL_WINDOWEVENT_FOCUS_LOST:
   3.780 +            fprintf(stderr, "Window %d lost keyboard focus",
   3.781 +                    event->window.windowID);
   3.782 +            break;
   3.783 +        default:
   3.784 +            fprintf(stderr, "Window %d got unknown event %d",
   3.785 +                    event->window.windowID, event->window.event);
   3.786 +            break;
   3.787 +        }
   3.788 +        break;
   3.789 +    case SDL_KEYDOWN:
   3.790 +        fprintf(stderr, "Keyboard %d: key %s pressed in window %d",
   3.791 +                event->key.which, SDL_GetKeyName(event->key.keysym.sym),
   3.792 +                event->key.windowID);
   3.793 +        break;
   3.794 +    case SDL_KEYUP:
   3.795 +        fprintf(stderr, "Keyboard %d: key %s released in window %d",
   3.796 +                event->key.which, SDL_GetKeyName(event->key.keysym.sym),
   3.797 +                event->key.windowID);
   3.798 +        break;
   3.799 +    case SDL_TEXTINPUT:
   3.800 +        fprintf(stderr, "Keyboard %d: text input \"%s\" in window %d",
   3.801 +                event->text.which, event->text.text, event->text.windowID);
   3.802 +        break;
   3.803 +    case SDL_MOUSEMOTION:
   3.804 +        fprintf(stderr, "Mouse %d: moved to %d,%d (%d,%d) in window %d",
   3.805 +                event->motion.which, event->motion.x, event->motion.y,
   3.806 +                event->motion.xrel, event->motion.yrel,
   3.807 +                event->motion.windowID);
   3.808 +        break;
   3.809 +    case SDL_MOUSEBUTTONDOWN:
   3.810 +        fprintf(stderr, "Mouse %d: button %d pressed at %d,%d in window %d",
   3.811 +                event->button.which, event->button.button, event->button.x,
   3.812 +                event->button.y, event->button.windowID);
   3.813 +        break;
   3.814 +    case SDL_MOUSEBUTTONUP:
   3.815 +        fprintf(stderr, "Mouse %d: button %d released at %d,%d in window %d",
   3.816 +                event->button.which, event->button.button, event->button.x,
   3.817 +                event->button.y, event->button.windowID);
   3.818 +        break;
   3.819 +    case SDL_MOUSEWHEEL:
   3.820 +        fprintf(stderr, "Mouse %d: wheel scrolled %d in window %d",
   3.821 +                event->wheel.which, event->wheel.motion,
   3.822 +                event->button.windowID);
   3.823 +        break;
   3.824 +    case SDL_JOYBALLMOTION:
   3.825 +        fprintf(stderr, "Joystick %d: ball %d moved by %d,%d",
   3.826 +                event->jball.which, event->jball.ball, event->jball.xrel,
   3.827 +                event->jball.yrel);
   3.828 +        break;
   3.829 +    case SDL_JOYHATMOTION:
   3.830 +        fprintf(stderr, "Joystick %d: hat %d moved to ", event->jhat.which,
   3.831 +                event->jhat.hat);
   3.832 +        switch (event->jhat.value) {
   3.833 +        case SDL_HAT_CENTERED:
   3.834 +            fprintf(stderr, "CENTER");
   3.835 +            break;
   3.836 +        case SDL_HAT_UP:
   3.837 +            fprintf(stderr, "UP");
   3.838 +            break;
   3.839 +        case SDL_HAT_RIGHTUP:
   3.840 +            fprintf(stderr, "RIGHTUP");
   3.841 +            break;
   3.842 +        case SDL_HAT_RIGHT:
   3.843 +            fprintf(stderr, "RIGHT");
   3.844 +            break;
   3.845 +        case SDL_HAT_RIGHTDOWN:
   3.846 +            fprintf(stderr, "RIGHTDOWN");
   3.847 +            break;
   3.848 +        case SDL_HAT_DOWN:
   3.849 +            fprintf(stderr, "DOWN");
   3.850 +            break;
   3.851 +        case SDL_HAT_LEFTDOWN:
   3.852 +            fprintf(stderr, "LEFTDOWN");
   3.853 +            break;
   3.854 +        case SDL_HAT_LEFT:
   3.855 +            fprintf(stderr, "LEFT");
   3.856 +            break;
   3.857 +        case SDL_HAT_LEFTUP:
   3.858 +            fprintf(stderr, "LEFTUP");
   3.859 +            break;
   3.860 +        default:
   3.861 +            fprintf(stderr, "UNKNOWN");
   3.862 +            break;
   3.863 +        }
   3.864 +        break;
   3.865 +    case SDL_JOYBUTTONDOWN:
   3.866 +        fprintf(stderr, "Joystick %d: button %d pressed",
   3.867 +                event->jbutton.which, event->jbutton.button);
   3.868 +        break;
   3.869 +    case SDL_JOYBUTTONUP:
   3.870 +        fprintf(stderr, "Joystick %d: button %d released",
   3.871 +                event->jbutton.which, event->jbutton.button);
   3.872 +        break;
   3.873 +    case SDL_QUIT:
   3.874 +        fprintf(stderr, "Quit requested");
   3.875 +        break;
   3.876 +    case SDL_USEREVENT:
   3.877 +        fprintf(stderr, "User event %d", event->user.code);
   3.878 +        break;
   3.879 +    default:
   3.880 +        fprintf(stderr, "Unknown event %d", event->type);
   3.881 +        break;
   3.882 +    }
   3.883 +    fprintf(stderr, "\n");
   3.884 +}
   3.885 +
   3.886 +void
   3.887 +CommonEvent(CommonState * state, SDL_Event * event, int *done)
   3.888 +{
   3.889 +    if (state->verbose & VERBOSE_EVENT) {
   3.890 +        PrintEvent(event);
   3.891 +    }
   3.892 +
   3.893 +    switch (event->type) {
   3.894 +    case SDL_WINDOWEVENT:
   3.895 +        switch (event->window.event) {
   3.896 +        case SDL_WINDOWEVENT_CLOSE:
   3.897 +            *done = 1;
   3.898 +            break;
   3.899 +        }
   3.900 +        break;
   3.901 +    case SDL_KEYDOWN:
   3.902 +        switch (event->key.keysym.sym) {
   3.903 +            /* Add hotkeys here */
   3.904 +        case SDLK_ESCAPE:
   3.905 +            *done = 1;
   3.906 +            break;
   3.907 +        default:
   3.908 +            break;
   3.909 +        }
   3.910 +        break;
   3.911 +    case SDL_QUIT:
   3.912 +        *done = 1;
   3.913 +        break;
   3.914 +    }
   3.915 +}
   3.916 +
   3.917 +void
   3.918 +CommonQuit(CommonState * state)
   3.919 +{
   3.920 +    if (state->flags & SDL_INIT_VIDEO) {
   3.921 +        SDL_VideoQuit();
   3.922 +    }
   3.923 +    if (state->flags & SDL_INIT_AUDIO) {
   3.924 +        SDL_AudioQuit();
   3.925 +    }
   3.926 +    if (state->windows) {
   3.927 +        SDL_free(state->windows);
   3.928 +    }
   3.929 +    SDL_free(state);
   3.930 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/common.h	Tue Jul 18 07:49:51 2006 +0000
     4.3 @@ -0,0 +1,47 @@
     4.4 +
     4.5 +/* A simple test program framework */
     4.6 +
     4.7 +#include "SDL.h"
     4.8 +
     4.9 +#define VERBOSE_VIDEO   0x00000001
    4.10 +#define VERBOSE_MODES   0x00000002
    4.11 +#define VERBOSE_RENDER  0x00000004
    4.12 +#define VERBOSE_EVENT   0x00000008
    4.13 +#define VERBOSE_AUDIO   0x00000010
    4.14 +
    4.15 +typedef struct
    4.16 +{
    4.17 +    /* SDL init flags */
    4.18 +    char **argv;
    4.19 +    Uint32 flags;
    4.20 +    Uint32 verbose;
    4.21 +
    4.22 +    /* Video info */
    4.23 +    const char *videodriver;
    4.24 +    int display;
    4.25 +    const char *window_title;
    4.26 +    Uint32 window_flags;
    4.27 +    int window_x;
    4.28 +    int window_y;
    4.29 +    int window_w;
    4.30 +    int window_h;
    4.31 +    int depth;
    4.32 +    int refresh_rate;
    4.33 +    int num_windows;
    4.34 +    SDL_WindowID *windows;
    4.35 +
    4.36 +    /* Renderer info */
    4.37 +    const char *renderdriver;
    4.38 +    Uint32 render_flags;
    4.39 +
    4.40 +    /* Audio info */
    4.41 +    const char *audiodriver;
    4.42 +    SDL_AudioSpec audiospec;
    4.43 +} CommonState;
    4.44 +
    4.45 +extern CommonState *CommonCreateState(char **argv, Uint32 flags);
    4.46 +extern int CommonArg(CommonState * state, int index);
    4.47 +extern const char *CommonUsage(CommonState * state);
    4.48 +extern SDL_bool CommonInit(CommonState * state);
    4.49 +extern void CommonEvent(CommonState * state, SDL_Event * event, int *done);
    4.50 +extern void CommonQuit(CommonState * state);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/testgl2.c	Tue Jul 18 07:49:51 2006 +0000
     5.3 @@ -0,0 +1,770 @@
     5.4 +#include <stdlib.h>
     5.5 +#include <stdio.h>
     5.6 +#include <string.h>
     5.7 +#include <math.h>
     5.8 +
     5.9 +#include "SDL.h"
    5.10 +
    5.11 +#ifdef __MACOS__
    5.12 +#define HAVE_OPENGL
    5.13 +#endif
    5.14 +
    5.15 +#ifdef HAVE_OPENGL
    5.16 +
    5.17 +#include "SDL_opengl.h"
    5.18 +
    5.19 +/* Undefine this if you want a flat cube instead of a rainbow cube */
    5.20 +#define SHADED_CUBE
    5.21 +
    5.22 +/* Define this to be the name of the logo image to use with -logo */
    5.23 +#define LOGO_FILE	"icon.bmp"
    5.24 +
    5.25 +static SDL_Surface *global_image = NULL;
    5.26 +static GLuint global_texture = 0;
    5.27 +static GLuint cursor_texture = 0;
    5.28 +
    5.29 +/**********************************************************************/
    5.30 +
    5.31 +void
    5.32 +HotKey_ToggleFullScreen(void)
    5.33 +{
    5.34 +    SDL_Surface *screen;
    5.35 +
    5.36 +    screen = SDL_GetVideoSurface();
    5.37 +    if (SDL_WM_ToggleFullScreen(screen)) {
    5.38 +        printf("Toggled fullscreen mode - now %s\n",
    5.39 +               (screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
    5.40 +    } else {
    5.41 +        printf("Unable to toggle fullscreen mode\n");
    5.42 +    }
    5.43 +}
    5.44 +
    5.45 +void
    5.46 +HotKey_ToggleGrab(void)
    5.47 +{
    5.48 +    SDL_GrabMode mode;
    5.49 +
    5.50 +    printf("Ctrl-G: toggling input grab!\n");
    5.51 +    mode = SDL_WM_GrabInput(SDL_GRAB_QUERY);
    5.52 +    if (mode == SDL_GRAB_ON) {
    5.53 +        printf("Grab was on\n");
    5.54 +    } else {
    5.55 +        printf("Grab was off\n");
    5.56 +    }
    5.57 +    mode = SDL_WM_GrabInput(!mode);
    5.58 +    if (mode == SDL_GRAB_ON) {
    5.59 +        printf("Grab is now on\n");
    5.60 +    } else {
    5.61 +        printf("Grab is now off\n");
    5.62 +    }
    5.63 +}
    5.64 +
    5.65 +void
    5.66 +HotKey_Iconify(void)
    5.67 +{
    5.68 +    printf("Ctrl-Z: iconifying window!\n");
    5.69 +    SDL_WM_IconifyWindow();
    5.70 +}
    5.71 +
    5.72 +int
    5.73 +HandleEvent(SDL_Event * event)
    5.74 +{
    5.75 +    int done;
    5.76 +
    5.77 +    done = 0;
    5.78 +    switch (event->type) {
    5.79 +    case SDL_ACTIVEEVENT:
    5.80 +        /* See what happened */
    5.81 +        printf("app %s ", event->active.gain ? "gained" : "lost");
    5.82 +        if (event->active.state & SDL_APPACTIVE) {
    5.83 +            printf("active ");
    5.84 +        } else if (event->active.state & SDL_APPMOUSEFOCUS) {
    5.85 +            printf("mouse ");
    5.86 +        } else if (event->active.state & SDL_APPINPUTFOCUS) {
    5.87 +            printf("input ");
    5.88 +        }
    5.89 +        printf("focus\n");
    5.90 +        break;
    5.91 +
    5.92 +
    5.93 +    case SDL_KEYDOWN:
    5.94 +        if (event->key.keysym.sym == SDLK_ESCAPE) {
    5.95 +            done = 1;
    5.96 +        }
    5.97 +        if ((event->key.keysym.sym == SDLK_g) &&
    5.98 +            (event->key.keysym.mod & KMOD_CTRL)) {
    5.99 +            HotKey_ToggleGrab();
   5.100 +        }
   5.101 +        if ((event->key.keysym.sym == SDLK_z) &&
   5.102 +            (event->key.keysym.mod & KMOD_CTRL)) {
   5.103 +            HotKey_Iconify();
   5.104 +        }
   5.105 +        if ((event->key.keysym.sym == SDLK_RETURN) &&
   5.106 +            (event->key.keysym.mod & KMOD_ALT)) {
   5.107 +            HotKey_ToggleFullScreen();
   5.108 +        }
   5.109 +        printf("key '%s' pressed\n", SDL_GetKeyName(event->key.keysym.sym));
   5.110 +        break;
   5.111 +    case SDL_QUIT:
   5.112 +        done = 1;
   5.113 +        break;
   5.114 +    }
   5.115 +    return (done);
   5.116 +}
   5.117 +
   5.118 +void
   5.119 +SDL_GL_Enter2DMode()
   5.120 +{
   5.121 +    SDL_Surface *screen = SDL_GetVideoSurface();
   5.122 +
   5.123 +    /* Note, there may be other things you need to change,
   5.124 +       depending on how you have your OpenGL state set up.
   5.125 +     */
   5.126 +    glPushAttrib(GL_ENABLE_BIT);
   5.127 +    glDisable(GL_DEPTH_TEST);
   5.128 +    glDisable(GL_CULL_FACE);
   5.129 +    glEnable(GL_TEXTURE_2D);
   5.130 +
   5.131 +    /* This allows alpha blending of 2D textures with the scene */
   5.132 +    glEnable(GL_BLEND);
   5.133 +    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   5.134 +
   5.135 +    glViewport(0, 0, screen->w, screen->h);
   5.136 +
   5.137 +    glMatrixMode(GL_PROJECTION);
   5.138 +    glPushMatrix();
   5.139 +    glLoadIdentity();
   5.140 +
   5.141 +    glOrtho(0.0, (GLdouble) screen->w, (GLdouble) screen->h, 0.0, 0.0, 1.0);
   5.142 +
   5.143 +    glMatrixMode(GL_MODELVIEW);
   5.144 +    glPushMatrix();
   5.145 +    glLoadIdentity();
   5.146 +
   5.147 +    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
   5.148 +}
   5.149 +
   5.150 +void
   5.151 +SDL_GL_Leave2DMode()
   5.152 +{
   5.153 +    glMatrixMode(GL_MODELVIEW);
   5.154 +    glPopMatrix();
   5.155 +
   5.156 +    glMatrixMode(GL_PROJECTION);
   5.157 +    glPopMatrix();
   5.158 +
   5.159 +    glPopAttrib();
   5.160 +}
   5.161 +
   5.162 +/* Quick utility function for texture creation */
   5.163 +static int
   5.164 +power_of_two(int input)
   5.165 +{
   5.166 +    int value = 1;
   5.167 +
   5.168 +    while (value < input) {
   5.169 +        value <<= 1;
   5.170 +    }
   5.171 +    return value;
   5.172 +}
   5.173 +
   5.174 +GLuint
   5.175 +SDL_GL_LoadTexture(SDL_Surface * surface, GLfloat * texcoord)
   5.176 +{
   5.177 +    GLuint texture;
   5.178 +    int w, h;
   5.179 +    SDL_Surface *image;
   5.180 +    SDL_Rect area;
   5.181 +    Uint32 saved_flags;
   5.182 +    Uint8 saved_alpha;
   5.183 +
   5.184 +    /* Use the surface width and height expanded to powers of 2 */
   5.185 +    w = power_of_two(surface->w);
   5.186 +    h = power_of_two(surface->h);
   5.187 +    texcoord[0] = 0.0f;         /* Min X */
   5.188 +    texcoord[1] = 0.0f;         /* Min Y */
   5.189 +    texcoord[2] = (GLfloat) surface->w / w;     /* Max X */
   5.190 +    texcoord[3] = (GLfloat) surface->h / h;     /* Max Y */
   5.191 +
   5.192 +    image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32,
   5.193 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN     /* OpenGL RGBA masks */
   5.194 +                                 0x000000FF,
   5.195 +                                 0x0000FF00, 0x00FF0000, 0xFF000000
   5.196 +#else
   5.197 +                                 0xFF000000,
   5.198 +                                 0x00FF0000, 0x0000FF00, 0x000000FF
   5.199 +#endif
   5.200 +        );
   5.201 +    if (image == NULL) {
   5.202 +        return 0;
   5.203 +    }
   5.204 +
   5.205 +    /* Save the alpha blending attributes */
   5.206 +    saved_flags = surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
   5.207 +    saved_alpha = surface->format->alpha;
   5.208 +    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   5.209 +        SDL_SetAlpha(surface, 0, 0);
   5.210 +    }
   5.211 +
   5.212 +    /* Copy the surface into the GL texture image */
   5.213 +    area.x = 0;
   5.214 +    area.y = 0;
   5.215 +    area.w = surface->w;
   5.216 +    area.h = surface->h;
   5.217 +    SDL_BlitSurface(surface, &area, image, &area);
   5.218 +
   5.219 +    /* Restore the alpha blending attributes */
   5.220 +    if ((saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
   5.221 +        SDL_SetAlpha(surface, saved_flags, saved_alpha);
   5.222 +    }
   5.223 +
   5.224 +    /* Create an OpenGL texture for the image */
   5.225 +    glGenTextures(1, &texture);
   5.226 +    glBindTexture(GL_TEXTURE_2D, texture);
   5.227 +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   5.228 +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
   5.229 +    glTexImage2D(GL_TEXTURE_2D,
   5.230 +                 0,
   5.231 +                 GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
   5.232 +    SDL_FreeSurface(image);     /* No longer needed */
   5.233 +
   5.234 +    return texture;
   5.235 +}
   5.236 +
   5.237 +void
   5.238 +DrawLogoCursor(void)
   5.239 +{
   5.240 +    static GLfloat texMinX, texMinY;
   5.241 +    static GLfloat texMaxX, texMaxY;
   5.242 +    static int w, h;
   5.243 +    int x, y;
   5.244 +
   5.245 +    if (!cursor_texture) {
   5.246 +        SDL_Surface *image;
   5.247 +        GLfloat texcoord[4];
   5.248 +
   5.249 +        /* Load the image (could use SDL_image library here) */
   5.250 +        image = SDL_LoadBMP(LOGO_FILE);
   5.251 +        if (image == NULL) {
   5.252 +            return;
   5.253 +        }
   5.254 +        w = image->w;
   5.255 +        h = image->h;
   5.256 +
   5.257 +        /* Convert the image into an OpenGL texture */
   5.258 +        cursor_texture = SDL_GL_LoadTexture(image, texcoord);
   5.259 +
   5.260 +        /* Make texture coordinates easy to understand */
   5.261 +        texMinX = texcoord[0];
   5.262 +        texMinY = texcoord[1];
   5.263 +        texMaxX = texcoord[2];
   5.264 +        texMaxY = texcoord[3];
   5.265 +
   5.266 +        /* We don't need the original image anymore */
   5.267 +        SDL_FreeSurface(image);
   5.268 +
   5.269 +        /* Make sure that the texture conversion is okay */
   5.270 +        if (!cursor_texture) {
   5.271 +            return;
   5.272 +        }
   5.273 +    }
   5.274 +
   5.275 +    /* Move the image around */
   5.276 +    SDL_GetMouseState(&x, &y);
   5.277 +    x -= w / 2;
   5.278 +    y -= h / 2;
   5.279 +
   5.280 +    /* Show the image on the screen */
   5.281 +    SDL_GL_Enter2DMode();
   5.282 +    glBindTexture(GL_TEXTURE_2D, cursor_texture);
   5.283 +    glBegin(GL_TRIANGLE_STRIP);
   5.284 +    glTexCoord2f(texMinX, texMinY);
   5.285 +    glVertex2i(x, y);
   5.286 +    glTexCoord2f(texMaxX, texMinY);
   5.287 +    glVertex2i(x + w, y);
   5.288 +    glTexCoord2f(texMinX, texMaxY);
   5.289 +    glVertex2i(x, y + h);
   5.290 +    glTexCoord2f(texMaxX, texMaxY);
   5.291 +    glVertex2i(x + w, y + h);
   5.292 +    glEnd();
   5.293 +    SDL_GL_Leave2DMode();
   5.294 +}
   5.295 +
   5.296 +void
   5.297 +DrawLogoTexture(void)
   5.298 +{
   5.299 +    static GLfloat texMinX, texMinY;
   5.300 +    static GLfloat texMaxX, texMaxY;
   5.301 +    static int x = 0;
   5.302 +    static int y = 0;
   5.303 +    static int w, h;
   5.304 +    static int delta_x = 1;
   5.305 +    static int delta_y = 1;
   5.306 +
   5.307 +    SDL_Surface *screen = SDL_GetVideoSurface();
   5.308 +
   5.309 +    if (!global_texture) {
   5.310 +        SDL_Surface *image;
   5.311 +        GLfloat texcoord[4];
   5.312 +
   5.313 +        /* Load the image (could use SDL_image library here) */
   5.314 +        image = SDL_LoadBMP(LOGO_FILE);
   5.315 +        if (image == NULL) {
   5.316 +            return;
   5.317 +        }
   5.318 +        w = image->w;
   5.319 +        h = image->h;
   5.320 +
   5.321 +        /* Convert the image into an OpenGL texture */
   5.322 +        global_texture = SDL_GL_LoadTexture(image, texcoord);
   5.323 +
   5.324 +        /* Make texture coordinates easy to understand */
   5.325 +        texMinX = texcoord[0];
   5.326 +        texMinY = texcoord[1];
   5.327 +        texMaxX = texcoord[2];
   5.328 +        texMaxY = texcoord[3];
   5.329 +
   5.330 +        /* We don't need the original image anymore */
   5.331 +        SDL_FreeSurface(image);
   5.332 +
   5.333 +        /* Make sure that the texture conversion is okay */
   5.334 +        if (!global_texture) {
   5.335 +            return;
   5.336 +        }
   5.337 +    }
   5.338 +
   5.339 +    /* Move the image around */
   5.340 +    x += delta_x;
   5.341 +    if (x < 0) {
   5.342 +        x = 0;
   5.343 +        delta_x = -delta_x;
   5.344 +    } else if ((x + w) > screen->w) {
   5.345 +        x = screen->w - w;
   5.346 +        delta_x = -delta_x;
   5.347 +    }
   5.348 +    y += delta_y;
   5.349 +    if (y < 0) {
   5.350 +        y = 0;
   5.351 +        delta_y = -delta_y;
   5.352 +    } else if ((y + h) > screen->h) {
   5.353 +        y = screen->h - h;
   5.354 +        delta_y = -delta_y;
   5.355 +    }
   5.356 +
   5.357 +    /* Show the image on the screen */
   5.358 +    SDL_GL_Enter2DMode();
   5.359 +    glBindTexture(GL_TEXTURE_2D, global_texture);
   5.360 +    glBegin(GL_TRIANGLE_STRIP);
   5.361 +    glTexCoord2f(texMinX, texMinY);
   5.362 +    glVertex2i(x, y);
   5.363 +    glTexCoord2f(texMaxX, texMinY);
   5.364 +    glVertex2i(x + w, y);
   5.365 +    glTexCoord2f(texMinX, texMaxY);
   5.366 +    glVertex2i(x, y + h);
   5.367 +    glTexCoord2f(texMaxX, texMaxY);
   5.368 +    glVertex2i(x + w, y + h);
   5.369 +    glEnd();
   5.370 +    SDL_GL_Leave2DMode();
   5.371 +}
   5.372 +
   5.373 +int
   5.374 +RunGLTest(int argc, char *argv[],
   5.375 +          int logo, int logocursor, int slowly, int bpp, float gamma,
   5.376 +          int noframe, int fsaa, int sync, int accel)
   5.377 +{
   5.378 +    int i;
   5.379 +    int rgb_size[3];
   5.380 +    int w = 640;
   5.381 +    int h = 480;
   5.382 +    int done = 0;
   5.383 +    int frames;
   5.384 +    Uint32 start_time, this_time;
   5.385 +    float color[8][3] = { {1.0, 1.0, 0.0},
   5.386 +    {1.0, 0.0, 0.0},
   5.387 +    {0.0, 0.0, 0.0},
   5.388 +    {0.0, 1.0, 0.0},
   5.389 +    {0.0, 1.0, 1.0},
   5.390 +    {1.0, 1.0, 1.0},
   5.391 +    {1.0, 0.0, 1.0},
   5.392 +    {0.0, 0.0, 1.0}
   5.393 +    };
   5.394 +    float cube[8][3] = { {0.5, 0.5, -0.5},
   5.395 +    {0.5, -0.5, -0.5},
   5.396 +    {-0.5, -0.5, -0.5},
   5.397 +    {-0.5, 0.5, -0.5},
   5.398 +    {-0.5, 0.5, 0.5},
   5.399 +    {0.5, 0.5, 0.5},
   5.400 +    {0.5, -0.5, 0.5},
   5.401 +    {-0.5, -0.5, 0.5}
   5.402 +    };
   5.403 +    Uint32 video_flags;
   5.404 +    int value;
   5.405 +
   5.406 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
   5.407 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
   5.408 +        exit(1);
   5.409 +    }
   5.410 +
   5.411 +    /* See if we should detect the display depth */
   5.412 +    if (bpp == 0) {
   5.413 +        if (SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8) {
   5.414 +            bpp = 8;
   5.415 +        } else {
   5.416 +            bpp = 16;           /* More doesn't seem to work */
   5.417 +        }
   5.418 +    }
   5.419 +
   5.420 +    /* Set the flags we want to use for setting the video mode */
   5.421 +    video_flags = SDL_OPENGL;
   5.422 +    for (i = 1; argv[i]; ++i) {
   5.423 +        if (strcmp(argv[i], "-fullscreen") == 0) {
   5.424 +            video_flags |= SDL_FULLSCREEN;
   5.425 +        }
   5.426 +    }
   5.427 +
   5.428 +    if (noframe) {
   5.429 +        video_flags |= SDL_NOFRAME;
   5.430 +    }
   5.431 +
   5.432 +    /* Initialize the display */
   5.433 +    switch (bpp) {
   5.434 +    case 8:
   5.435 +        rgb_size[0] = 3;
   5.436 +        rgb_size[1] = 3;
   5.437 +        rgb_size[2] = 2;
   5.438 +        break;
   5.439 +    case 15:
   5.440 +    case 16:
   5.441 +        rgb_size[0] = 5;
   5.442 +        rgb_size[1] = 5;
   5.443 +        rgb_size[2] = 5;
   5.444 +        break;
   5.445 +    default:
   5.446 +        rgb_size[0] = 8;
   5.447 +        rgb_size[1] = 8;
   5.448 +        rgb_size[2] = 8;
   5.449 +        break;
   5.450 +    }
   5.451 +    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, rgb_size[0]);
   5.452 +    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, rgb_size[1]);
   5.453 +    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, rgb_size[2]);
   5.454 +    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
   5.455 +    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
   5.456 +    if (fsaa) {
   5.457 +        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
   5.458 +        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, fsaa);
   5.459 +    }
   5.460 +    if (accel) {
   5.461 +        SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
   5.462 +    }
   5.463 +    if (SDL_SetVideoMode(w, h, bpp, video_flags) == NULL) {
   5.464 +        fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
   5.465 +        SDL_Quit();
   5.466 +        exit(1);
   5.467 +    }
   5.468 +    if (sync) {
   5.469 +        SDL_GL_SetSwapInterval(1);
   5.470 +    } else {
   5.471 +        SDL_GL_SetSwapInterval(0);
   5.472 +    }
   5.473 +
   5.474 +    printf("Screen BPP: %d\n", SDL_GetVideoSurface()->format->BitsPerPixel);
   5.475 +    printf("\n");
   5.476 +    printf("Vendor     : %s\n", glGetString(GL_VENDOR));
   5.477 +    printf("Renderer   : %s\n", glGetString(GL_RENDERER));
   5.478 +    printf("Version    : %s\n", glGetString(GL_VERSION));
   5.479 +    printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
   5.480 +    printf("\n");
   5.481 +
   5.482 +    SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   5.483 +    printf("SDL_GL_RED_SIZE: requested %d, got %d\n", rgb_size[0], value);
   5.484 +    SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   5.485 +    printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", rgb_size[1], value);
   5.486 +    SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   5.487 +    printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", rgb_size[2], value);
   5.488 +    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   5.489 +    printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", bpp, value);
   5.490 +    SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value);
   5.491 +    printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
   5.492 +    if (fsaa) {
   5.493 +        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   5.494 +        printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   5.495 +        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   5.496 +        printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
   5.497 +               value);
   5.498 +    }
   5.499 +    if (accel) {
   5.500 +        SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   5.501 +        printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   5.502 +    }
   5.503 +    if (sync) {
   5.504 +        printf("Buffer swap interval: requested 1, got %d\n",
   5.505 +               SDL_GL_GetSwapInterval());
   5.506 +    }
   5.507 +
   5.508 +    /* Set the window manager title bar */
   5.509 +    SDL_WM_SetCaption("SDL GL test", "testgl");
   5.510 +
   5.511 +    /* Set the gamma for the window */
   5.512 +    if (gamma != 0.0) {
   5.513 +        SDL_SetGamma(gamma, gamma, gamma);
   5.514 +    }
   5.515 +
   5.516 +    glViewport(0, 0, w, h);
   5.517 +    glMatrixMode(GL_PROJECTION);
   5.518 +    glLoadIdentity();
   5.519 +
   5.520 +    glOrtho(-2.0, 2.0, -2.0, 2.0, -20.0, 20.0);
   5.521 +
   5.522 +    glMatrixMode(GL_MODELVIEW);
   5.523 +    glLoadIdentity();
   5.524 +
   5.525 +    glEnable(GL_DEPTH_TEST);
   5.526 +
   5.527 +    glDepthFunc(GL_LESS);
   5.528 +
   5.529 +    glShadeModel(GL_SMOOTH);
   5.530 +
   5.531 +    /* Loop until done. */
   5.532 +    start_time = SDL_GetTicks();
   5.533 +    frames = 0;
   5.534 +    while (!done) {
   5.535 +        GLenum gl_error;
   5.536 +        char *sdl_error;
   5.537 +        SDL_Event event;
   5.538 +
   5.539 +        /* Do our drawing, too. */
   5.540 +        glClearColor(0.0, 0.0, 0.0, 1.0);
   5.541 +        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   5.542 +
   5.543 +        glBegin(GL_QUADS);
   5.544 +
   5.545 +#ifdef SHADED_CUBE
   5.546 +        glColor3fv(color[0]);
   5.547 +        glVertex3fv(cube[0]);
   5.548 +        glColor3fv(color[1]);
   5.549 +        glVertex3fv(cube[1]);
   5.550 +        glColor3fv(color[2]);
   5.551 +        glVertex3fv(cube[2]);
   5.552 +        glColor3fv(color[3]);
   5.553 +        glVertex3fv(cube[3]);
   5.554 +
   5.555 +        glColor3fv(color[3]);
   5.556 +        glVertex3fv(cube[3]);
   5.557 +        glColor3fv(color[4]);
   5.558 +        glVertex3fv(cube[4]);
   5.559 +        glColor3fv(color[7]);
   5.560 +        glVertex3fv(cube[7]);
   5.561 +        glColor3fv(color[2]);
   5.562 +        glVertex3fv(cube[2]);
   5.563 +
   5.564 +        glColor3fv(color[0]);
   5.565 +        glVertex3fv(cube[0]);
   5.566 +        glColor3fv(color[5]);
   5.567 +        glVertex3fv(cube[5]);
   5.568 +        glColor3fv(color[6]);
   5.569 +        glVertex3fv(cube[6]);
   5.570 +        glColor3fv(color[1]);
   5.571 +        glVertex3fv(cube[1]);
   5.572 +
   5.573 +        glColor3fv(color[5]);
   5.574 +        glVertex3fv(cube[5]);
   5.575 +        glColor3fv(color[4]);
   5.576 +        glVertex3fv(cube[4]);
   5.577 +        glColor3fv(color[7]);
   5.578 +        glVertex3fv(cube[7]);
   5.579 +        glColor3fv(color[6]);
   5.580 +        glVertex3fv(cube[6]);
   5.581 +
   5.582 +        glColor3fv(color[5]);
   5.583 +        glVertex3fv(cube[5]);
   5.584 +        glColor3fv(color[0]);
   5.585 +        glVertex3fv(cube[0]);
   5.586 +        glColor3fv(color[3]);
   5.587 +        glVertex3fv(cube[3]);
   5.588 +        glColor3fv(color[4]);
   5.589 +        glVertex3fv(cube[4]);
   5.590 +
   5.591 +        glColor3fv(color[6]);
   5.592 +        glVertex3fv(cube[6]);
   5.593 +        glColor3fv(color[1]);
   5.594 +        glVertex3fv(cube[1]);
   5.595 +        glColor3fv(color[2]);
   5.596 +        glVertex3fv(cube[2]);
   5.597 +        glColor3fv(color[7]);
   5.598 +        glVertex3fv(cube[7]);
   5.599 +#else /* flat cube */
   5.600 +        glColor3f(1.0, 0.0, 0.0);
   5.601 +        glVertex3fv(cube[0]);
   5.602 +        glVertex3fv(cube[1]);
   5.603 +        glVertex3fv(cube[2]);
   5.604 +        glVertex3fv(cube[3]);
   5.605 +
   5.606 +        glColor3f(0.0, 1.0, 0.0);
   5.607 +        glVertex3fv(cube[3]);
   5.608 +        glVertex3fv(cube[4]);
   5.609 +        glVertex3fv(cube[7]);
   5.610 +        glVertex3fv(cube[2]);
   5.611 +
   5.612 +        glColor3f(0.0, 0.0, 1.0);
   5.613 +        glVertex3fv(cube[0]);
   5.614 +        glVertex3fv(cube[5]);
   5.615 +        glVertex3fv(cube[6]);
   5.616 +        glVertex3fv(cube[1]);
   5.617 +
   5.618 +        glColor3f(0.0, 1.0, 1.0);
   5.619 +        glVertex3fv(cube[5]);
   5.620 +        glVertex3fv(cube[4]);
   5.621 +        glVertex3fv(cube[7]);
   5.622 +        glVertex3fv(cube[6]);
   5.623 +
   5.624 +        glColor3f(1.0, 1.0, 0.0);
   5.625 +        glVertex3fv(cube[5]);
   5.626 +        glVertex3fv(cube[0]);
   5.627 +        glVertex3fv(cube[3]);
   5.628 +        glVertex3fv(cube[4]);
   5.629 +
   5.630 +        glColor3f(1.0, 0.0, 1.0);
   5.631 +        glVertex3fv(cube[6]);
   5.632 +        glVertex3fv(cube[1]);
   5.633 +        glVertex3fv(cube[2]);
   5.634 +        glVertex3fv(cube[7]);
   5.635 +#endif /* SHADED_CUBE */
   5.636 +
   5.637 +        glEnd();
   5.638 +
   5.639 +        glMatrixMode(GL_MODELVIEW);
   5.640 +        glRotatef(5.0, 1.0, 1.0, 1.0);
   5.641 +
   5.642 +        /* Draw 2D logo onto the 3D display */
   5.643 +        if (logo) {
   5.644 +            DrawLogoTexture();
   5.645 +        }
   5.646 +        if (logocursor) {
   5.647 +            DrawLogoCursor();
   5.648 +        }
   5.649 +
   5.650 +        SDL_GL_SwapBuffers();
   5.651 +
   5.652 +        /* Check for error conditions. */
   5.653 +        gl_error = glGetError();
   5.654 +
   5.655 +        if (gl_error != GL_NO_ERROR) {
   5.656 +            fprintf(stderr, "testgl: OpenGL error: %d\n", gl_error);
   5.657 +        }
   5.658 +
   5.659 +        sdl_error = SDL_GetError();
   5.660 +
   5.661 +        if (sdl_error[0] != '\0') {
   5.662 +            fprintf(stderr, "testgl: SDL error '%s'\n", sdl_error);
   5.663 +            SDL_ClearError();
   5.664 +        }
   5.665 +
   5.666 +        /* Allow the user to see what's happening */
   5.667 +        if (slowly) {
   5.668 +            SDL_Delay(20);
   5.669 +        }
   5.670 +
   5.671 +        /* Check if there's a pending event. */
   5.672 +        while (SDL_PollEvent(&event)) {
   5.673 +            done = HandleEvent(&event);
   5.674 +        }
   5.675 +        ++frames;
   5.676 +    }
   5.677 +
   5.678 +    /* Print out the frames per second */
   5.679 +    this_time = SDL_GetTicks();
   5.680 +    if (this_time != start_time) {
   5.681 +        printf("%2.2f FPS\n",
   5.682 +               ((float) frames / (this_time - start_time)) * 1000.0);
   5.683 +    }
   5.684 +
   5.685 +    if (global_image) {
   5.686 +        SDL_FreeSurface(global_image);
   5.687 +        global_image = NULL;
   5.688 +    }
   5.689 +    if (global_texture) {
   5.690 +        glDeleteTextures(1, &global_texture);
   5.691 +        global_texture = 0;
   5.692 +    }
   5.693 +    if (cursor_texture) {
   5.694 +        glDeleteTextures(1, &cursor_texture);
   5.695 +        cursor_texture = 0;
   5.696 +    }
   5.697 +
   5.698 +    /* Destroy our GL context, etc. */
   5.699 +    SDL_Quit();
   5.700 +    return (0);
   5.701 +}
   5.702 +
   5.703 +int
   5.704 +main(int argc, char *argv[])
   5.705 +{
   5.706 +    int i, logo, logocursor = 0;
   5.707 +    int numtests;
   5.708 +    int bpp = 0;
   5.709 +    int slowly;
   5.710 +    float gamma = 0.0;
   5.711 +    int noframe = 0;
   5.712 +    int fsaa = 0;
   5.713 +    int accel = 0;
   5.714 +    int sync = 0;
   5.715 +
   5.716 +    logo = 0;
   5.717 +    slowly = 0;
   5.718 +    numtests = 1;
   5.719 +    for (i = 1; argv[i]; ++i) {
   5.720 +        if (strcmp(argv[i], "-twice") == 0) {
   5.721 +            ++numtests;
   5.722 +        }
   5.723 +        if (strcmp(argv[i], "-logo") == 0) {
   5.724 +            logo = 1;
   5.725 +        }
   5.726 +        if (strcmp(argv[i], "-logocursor") == 0) {
   5.727 +            logocursor = 1;
   5.728 +        }
   5.729 +        if (strcmp(argv[i], "-slow") == 0) {
   5.730 +            slowly = 1;
   5.731 +        }
   5.732 +        if (strcmp(argv[i], "-bpp") == 0) {
   5.733 +            bpp = atoi(argv[++i]);
   5.734 +        }
   5.735 +        if (strcmp(argv[i], "-gamma") == 0) {
   5.736 +            gamma = (float) atof(argv[++i]);
   5.737 +        }
   5.738 +        if (strcmp(argv[i], "-noframe") == 0) {
   5.739 +            noframe = 1;
   5.740 +        }
   5.741 +        if (strcmp(argv[i], "-fsaa") == 0) {
   5.742 +            ++fsaa;
   5.743 +        }
   5.744 +        if (strcmp(argv[i], "-accel") == 0) {
   5.745 +            ++accel;
   5.746 +        }
   5.747 +        if (strcmp(argv[i], "-sync") == 0) {
   5.748 +            ++sync;
   5.749 +        }
   5.750 +        if (strncmp(argv[i], "-h", 2) == 0) {
   5.751 +            printf
   5.752 +                ("Usage: %s [-twice] [-logo] [-logocursor] [-slow] [-bpp n] [-gamma n] [-noframe] [-fsaa] [-accel] [-sync] [-fullscreen]\n",
   5.753 +                 argv[0]);
   5.754 +            exit(0);
   5.755 +        }
   5.756 +    }
   5.757 +    for (i = 0; i < numtests; ++i) {
   5.758 +        RunGLTest(argc, argv, logo, logocursor, slowly, bpp, gamma,
   5.759 +                  noframe, fsaa, sync, accel);
   5.760 +    }
   5.761 +    return 0;
   5.762 +}
   5.763 +
   5.764 +#else /* HAVE_OPENGL */
   5.765 +
   5.766 +int
   5.767 +main(int argc, char *argv[])
   5.768 +{
   5.769 +    printf("No OpenGL support on this system\n");
   5.770 +    return 1;
   5.771 +}
   5.772 +
   5.773 +#endif /* HAVE_OPENGL */
     6.1 --- a/test/testsprite2.c	Mon Jul 17 06:47:33 2006 +0000
     6.2 +++ b/test/testsprite2.c	Tue Jul 18 07:49:51 2006 +0000
     6.3 @@ -4,18 +4,14 @@
     6.4  #include <stdio.h>
     6.5  #include <time.h>
     6.6  
     6.7 -#include "SDL.h"
     6.8 +#include "common.h"
     6.9  
    6.10 -#define NUM_WINDOWS 4
    6.11 -#define WINDOW_W    640
    6.12 -#define WINDOW_H    480
    6.13  #define NUM_SPRITES	100
    6.14  #define MAX_SPEED 	1
    6.15  #define BACKGROUND  0x00FFFFFF
    6.16  
    6.17 -static int num_windows;
    6.18 +static CommonState *state;
    6.19  static int num_sprites;
    6.20 -static SDL_WindowID *windows;
    6.21  static SDL_TextureID *sprites;
    6.22  static SDL_Rect *positions;
    6.23  static SDL_Rect *velocities;
    6.24 @@ -25,9 +21,6 @@
    6.25  static void
    6.26  quit(int rc)
    6.27  {
    6.28 -    if (windows) {
    6.29 -        SDL_free(windows);
    6.30 -    }
    6.31      if (sprites) {
    6.32          SDL_free(sprites);
    6.33      }
    6.34 @@ -37,7 +30,7 @@
    6.35      if (velocities) {
    6.36          SDL_free(velocities);
    6.37      }
    6.38 -    SDL_Quit();
    6.39 +    CommonQuit(state);
    6.40      exit(rc);
    6.41  }
    6.42  
    6.43 @@ -62,8 +55,8 @@
    6.44      }
    6.45  
    6.46      /* Create textures from the image */
    6.47 -    for (i = 0; i < num_windows; ++i) {
    6.48 -        SDL_SelectRenderer(windows[i]);
    6.49 +    for (i = 0; i < state->num_windows; ++i) {
    6.50 +        SDL_SelectRenderer(state->windows[i]);
    6.51          sprites[i] =
    6.52              SDL_CreateTextureFromSurface(0, SDL_TextureAccess_Remote, temp);
    6.53          if (!sprites[i]) {
    6.54 @@ -125,78 +118,45 @@
    6.55  int
    6.56  main(int argc, char *argv[])
    6.57  {
    6.58 -    int window_w, window_h;
    6.59 -    Uint32 window_flags = SDL_WINDOW_SHOWN;
    6.60 -    Uint32 render_flags = 0;
    6.61 -    SDL_DisplayMode *mode, fullscreen_mode;
    6.62      int i, done;
    6.63      SDL_Event event;
    6.64      Uint32 then, now, frames;
    6.65  
    6.66 -    /* Initialize SDL */
    6.67 -    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    6.68 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    6.69 -        return (1);
    6.70 +    /* Initialize parameters */
    6.71 +    num_sprites = NUM_SPRITES;
    6.72 +
    6.73 +    /* Initialize test framework */
    6.74 +    state = CommonCreateState(argv, SDL_INIT_VIDEO);
    6.75 +    if (!state) {
    6.76 +        return 1;
    6.77      }
    6.78 +    for (i = 1; i < argc;) {
    6.79 +        int consumed;
    6.80  
    6.81 -    num_windows = NUM_WINDOWS;
    6.82 -    num_sprites = NUM_SPRITES;
    6.83 -    window_w = WINDOW_W;
    6.84 -    window_h = WINDOW_H;
    6.85 -    for (i = 1; i < argc; ++i) {
    6.86 -        if (strcmp(argv[i], "-width") == 0 && (i + 1 < argc)) {
    6.87 -            window_w = atoi(argv[++i]);
    6.88 -        } else if (strcmp(argv[i], "-height") == 0 && (i + 1 < argc)) {
    6.89 -            window_h = atoi(argv[++i]);
    6.90 -        } else if (strcmp(argv[i], "-windows") == 0 && (i + 1 < argc)) {
    6.91 -            num_windows = atoi(argv[++i]);
    6.92 -            window_flags &= ~SDL_WINDOW_FULLSCREEN;
    6.93 -        } else if (strcmp(argv[i], "-fullscreen") == 0) {
    6.94 -            num_windows = 1;
    6.95 -            window_flags |= SDL_WINDOW_FULLSCREEN;
    6.96 -        } else if (strcmp(argv[i], "-sync") == 0) {
    6.97 -            render_flags |= SDL_Renderer_PresentVSync;
    6.98 -        } else if (isdigit(argv[i][0])) {
    6.99 -            num_sprites = atoi(argv[i]);
   6.100 -        } else {
   6.101 -            fprintf(stderr,
   6.102 -                    "Usage: %s [-width N] [-height N] [-windows N] [-fullscreen] [-sync] [numsprites]\n",
   6.103 -                    argv[0]);
   6.104 +        consumed = CommonArg(state, i);
   6.105 +        if (consumed < 0) {
   6.106 +            fprintf(stderr, "Usage: %s %s", argv[0], CommonUsage(state));
   6.107              quit(1);
   6.108          }
   6.109 +        if (consumed == 0) {
   6.110 +            num_sprites = SDL_atoi(argv[i]);
   6.111 +            consumed = 1;
   6.112 +        }
   6.113 +        i += consumed;
   6.114      }
   6.115 -
   6.116 -    if (window_flags & SDL_WINDOW_FULLSCREEN) {
   6.117 -        SDL_zero(fullscreen_mode);
   6.118 -        fullscreen_mode.w = window_w;
   6.119 -        fullscreen_mode.h = window_h;
   6.120 -        SDL_SetFullscreenDisplayMode(&fullscreen_mode);
   6.121 +    if (!CommonInit(state)) {
   6.122 +        quit(2);
   6.123      }
   6.124  
   6.125      /* Create the windows, initialize the renderers, and load the textures */
   6.126 -    windows = (SDL_WindowID *) SDL_malloc(num_windows * sizeof(*windows));
   6.127 -    sprites = (SDL_TextureID *) SDL_malloc(num_windows * sizeof(*sprites));
   6.128 -    if (!windows || !sprites) {
   6.129 +    sprites =
   6.130 +        (SDL_TextureID *) SDL_malloc(state->num_windows * sizeof(*sprites));
   6.131 +    if (!sprites) {
   6.132          fprintf(stderr, "Out of memory!\n");
   6.133          quit(2);
   6.134      }
   6.135 -    for (i = 0; i < num_windows; ++i) {
   6.136 -        char title[32];
   6.137 -
   6.138 -        SDL_snprintf(title, sizeof(title), "testsprite %d", i + 1);
   6.139 -        windows[i] =
   6.140 -            SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED,
   6.141 -                             SDL_WINDOWPOS_UNDEFINED, window_w, window_h,
   6.142 -                             window_flags);
   6.143 -        if (!windows[i]) {
   6.144 -            fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
   6.145 -            quit(2);
   6.146 -        }
   6.147 -
   6.148 -        if (SDL_CreateRenderer(windows[i], -1, render_flags) < 0) {
   6.149 -            fprintf(stderr, "Couldn't create renderer: %s\n", SDL_GetError());
   6.150 -            quit(2);
   6.151 -        }
   6.152 +    for (i = 0; i < state->num_windows; ++i) {
   6.153 +        SDL_SelectRenderer(state->windows[i]);
   6.154          SDL_RenderFill(NULL, BACKGROUND);
   6.155      }
   6.156      if (LoadSprite("icon.bmp") < 0) {
   6.157 @@ -212,8 +172,8 @@
   6.158      }
   6.159      srand(time(NULL));
   6.160      for (i = 0; i < num_sprites; ++i) {
   6.161 -        positions[i].x = rand() % (window_w - sprite_w);
   6.162 -        positions[i].y = rand() % (window_h - sprite_h);
   6.163 +        positions[i].x = rand() % (state->window_w - sprite_w);
   6.164 +        positions[i].y = rand() % (state->window_h - sprite_h);
   6.165          positions[i].w = sprite_w;
   6.166          positions[i].h = sprite_h;
   6.167          velocities[i].x = 0;
   6.168 @@ -232,6 +192,7 @@
   6.169          /* Check for events */
   6.170          ++frames;
   6.171          while (SDL_PollEvent(&event)) {
   6.172 +            CommonEvent(state, &event, &done);
   6.173              switch (event.type) {
   6.174              case SDL_WINDOWEVENT:
   6.175                  switch (event.window.event) {
   6.176 @@ -239,22 +200,14 @@
   6.177                      SDL_SelectRenderer(event.window.windowID);
   6.178                      SDL_RenderFill(NULL, BACKGROUND);
   6.179                      break;
   6.180 -                case SDL_WINDOWEVENT_CLOSE:
   6.181 -                    done = 1;
   6.182 -                    break;
   6.183                  }
   6.184                  break;
   6.185 -            case SDL_KEYDOWN:
   6.186 -                /* Any keypress quits the app... */
   6.187 -            case SDL_QUIT:
   6.188 -                done = 1;
   6.189 -                break;
   6.190              default:
   6.191                  break;
   6.192              }
   6.193          }
   6.194 -        for (i = 0; i < num_windows; ++i) {
   6.195 -            MoveSprites(windows[i], sprites[i]);
   6.196 +        for (i = 0; i < state->num_windows; ++i) {
   6.197 +            MoveSprites(state->windows[i], sprites[i]);
   6.198          }
   6.199      }
   6.200