test/testdraw2.c
changeset 9278 8900afb78a19
parent 8149 681eb46b8ac4
child 9607 7746ab058d12
--- a/test/testdraw2.c	Sat Dec 13 02:33:52 2014 -0500
+++ b/test/testdraw2.c	Thu Dec 18 00:19:52 2014 -0500
@@ -16,6 +16,10 @@
 #include <stdio.h>
 #include <time.h>
 
+#ifdef __EMSCRIPTEN__
+#include <emscripten/emscripten.h>
+#endif
+
 #include "SDL_test_common.h"
 
 #define NUM_OBJECTS 100
@@ -29,6 +33,8 @@
 static int current_color = 255;
 static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
 
+int done;
+
 void
 DrawPoints(SDL_Renderer * renderer)
 {
@@ -169,11 +175,35 @@
     }
 }
 
+void
+loop()
+{
+    int i;
+    SDL_Event event;
+
+    /* Check for events */
+    while (SDL_PollEvent(&event)) {
+        SDLTest_CommonEvent(state, &event, &done);
+    }
+    for (i = 0; i < state->num_windows; ++i) {
+        SDL_Renderer *renderer = state->renderers[i];
+        if (state->windows[i] == NULL)
+            continue;
+        SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
+        SDL_RenderClear(renderer);
+
+        DrawRects(renderer);
+        DrawLines(renderer);
+        DrawPoints(renderer);
+
+        SDL_RenderPresent(renderer);
+    }
+}
+
 int
 main(int argc, char *argv[])
 {
-    int i, done;
-    SDL_Event event;
+    int i;
     Uint32 then, now, frames;
 
 	/* Enable standard application logging */
@@ -245,26 +275,16 @@
     frames = 0;
     then = SDL_GetTicks();
     done = 0;
+
+#ifdef __EMSCRIPTEN__
+    emscripten_set_main_loop(loop, 0, 1);
+#else
     while (!done) {
-        /* Check for events */
         ++frames;
-        while (SDL_PollEvent(&event)) {
-            SDLTest_CommonEvent(state, &event, &done);
+        loop();
         }
-        for (i = 0; i < state->num_windows; ++i) {
-            SDL_Renderer *renderer = state->renderers[i];
-            if (state->windows[i] == NULL)
-                continue;
-            SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
-            SDL_RenderClear(renderer);
+#endif
 
-            DrawRects(renderer);
-            DrawLines(renderer);
-            DrawPoints(renderer);
-
-            SDL_RenderPresent(renderer);
-        }
-    }
 
     SDLTest_CommonQuit(state);