test/testdraw2.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
child 9607 7746ab058d12
     1.1 --- a/test/testdraw2.c	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/test/testdraw2.c	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -16,6 +16,10 @@
     1.4  #include <stdio.h>
     1.5  #include <time.h>
     1.6  
     1.7 +#ifdef __EMSCRIPTEN__
     1.8 +#include <emscripten/emscripten.h>
     1.9 +#endif
    1.10 +
    1.11  #include "SDL_test_common.h"
    1.12  
    1.13  #define NUM_OBJECTS 100
    1.14 @@ -29,6 +33,8 @@
    1.15  static int current_color = 255;
    1.16  static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
    1.17  
    1.18 +int done;
    1.19 +
    1.20  void
    1.21  DrawPoints(SDL_Renderer * renderer)
    1.22  {
    1.23 @@ -169,11 +175,35 @@
    1.24      }
    1.25  }
    1.26  
    1.27 +void
    1.28 +loop()
    1.29 +{
    1.30 +    int i;
    1.31 +    SDL_Event event;
    1.32 +
    1.33 +    /* Check for events */
    1.34 +    while (SDL_PollEvent(&event)) {
    1.35 +        SDLTest_CommonEvent(state, &event, &done);
    1.36 +    }
    1.37 +    for (i = 0; i < state->num_windows; ++i) {
    1.38 +        SDL_Renderer *renderer = state->renderers[i];
    1.39 +        if (state->windows[i] == NULL)
    1.40 +            continue;
    1.41 +        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.42 +        SDL_RenderClear(renderer);
    1.43 +
    1.44 +        DrawRects(renderer);
    1.45 +        DrawLines(renderer);
    1.46 +        DrawPoints(renderer);
    1.47 +
    1.48 +        SDL_RenderPresent(renderer);
    1.49 +    }
    1.50 +}
    1.51 +
    1.52  int
    1.53  main(int argc, char *argv[])
    1.54  {
    1.55 -    int i, done;
    1.56 -    SDL_Event event;
    1.57 +    int i;
    1.58      Uint32 then, now, frames;
    1.59  
    1.60  	/* Enable standard application logging */
    1.61 @@ -245,26 +275,16 @@
    1.62      frames = 0;
    1.63      then = SDL_GetTicks();
    1.64      done = 0;
    1.65 +
    1.66 +#ifdef __EMSCRIPTEN__
    1.67 +    emscripten_set_main_loop(loop, 0, 1);
    1.68 +#else
    1.69      while (!done) {
    1.70 -        /* Check for events */
    1.71          ++frames;
    1.72 -        while (SDL_PollEvent(&event)) {
    1.73 -            SDLTest_CommonEvent(state, &event, &done);
    1.74 +        loop();
    1.75          }
    1.76 -        for (i = 0; i < state->num_windows; ++i) {
    1.77 -            SDL_Renderer *renderer = state->renderers[i];
    1.78 -            if (state->windows[i] == NULL)
    1.79 -                continue;
    1.80 -            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
    1.81 -            SDL_RenderClear(renderer);
    1.82 +#endif
    1.83  
    1.84 -            DrawRects(renderer);
    1.85 -            DrawLines(renderer);
    1.86 -            DrawPoints(renderer);
    1.87 -
    1.88 -            SDL_RenderPresent(renderer);
    1.89 -        }
    1.90 -    }
    1.91  
    1.92      SDLTest_CommonQuit(state);
    1.93