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
This commit is contained in:
Sam Lantinga 2024-07-23 08:34:15 -07:00
parent b499c54af4
commit ff7a60db85
1 changed files with 4 additions and 5 deletions

View File

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