Sfoglia il codice sorgente

Minor fixes to the primitive example

* The random number generator is automatically seeded, no need for SDL_srand()
* Draw the points first, so they don't overlap the other primitives and look like broken line drawing
Sam Lantinga 9 mesi fa
parent
commit
ff7a60db85
1 ha cambiato i file con 4 aggiunte e 5 eliminazioni
  1. 4 5
      examples/renderer/02-primitives/renderer-primitives.c

+ 4 - 5
examples/renderer/02-primitives/renderer-primitives.c

@@ -25,7 +25,6 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
     }
 
     /* set up some random points */
-    SDL_srand(0);  /* seed the random number generator with current time */
     for (i = 0; i < SDL_arraysize(points); i++) {
         points[i].x = (SDL_randf() * 440.0f) + 100.0f;
         points[i].y = (SDL_randf() * 280.0f) + 100.0f;
@@ -59,6 +58,10 @@ int SDL_AppIterate(void *appstate)
     rect.h = 280;
     SDL_RenderFillRect(renderer, &rect);
 
+    /* draw some points across the canvas. */
+    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);  /* red, full alpha */
+    SDL_RenderPoints(renderer, points, SDL_arraysize(points));
+
     /* draw a unfilled rectangle in-set a little bit. */
     SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255);  /* green, full alpha */
     rect.x += 30;
@@ -72,10 +75,6 @@ int SDL_AppIterate(void *appstate)
     SDL_RenderLine(renderer, 0, 0, 640, 480);
     SDL_RenderLine(renderer, 0, 480, 640, 0);
 
-    /* draw some points across the canvas. */
-    SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);  /* red, full alpha */
-    SDL_RenderPoints(renderer, points, SDL_arraysize(points));
-
     SDL_RenderPresent(renderer);  /* put it all on the screen! */
 
     return SDL_APP_CONTINUE;  /* carry on with the program! */