diff options
author | kdx <kikoodx@paranoici.org> | 2022-09-12 11:55:22 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2022-09-12 11:55:22 +0200 |
commit | 91ddea20e60895f57417dcac1b523be2292c5c19 (patch) | |
tree | 02b40c20b0db93845a575616ab82f89f4eeda7c8 | |
parent | 1e9864e62f699d5d720e67ecedbd1dc325db26fe (diff) | |
download | lzr-91ddea20e60895f57417dcac1b523be2292c5c19.tar.gz |
draw points
-rw-r--r-- | lzr.c | 30 | ||||
-rw-r--r-- | lzr.h | 1 |
2 files changed, 31 insertions, 0 deletions
@@ -30,6 +30,7 @@ static unsigned int map[LZR_BUTTON_COUNT] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_X, SDL_SCANCODE_C}; static bool input[LZR_BUTTON_COUNT] = {false}; +static SDL_Point *points = NULL; static char *_path_prefix(const char *path) { @@ -179,6 +180,12 @@ int LZR_Init(LZR_Config cfg) dx_log_error("%s", SDL_GetError()); return -1; } + points = dx_alloc(sizeof(SDL_Point) * cfg.display_width * + cfg.display_height); + if (points == NULL) { + dx_log_error("dx_alloc failed"); + return -1; + } SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 0); if (config.target_fps) { min_dt = 1000 / config.target_fps; @@ -195,6 +202,10 @@ void LZR_Quit(void) images[i].tex = NULL; dx_log_trace("destroyed image %d", i); } + if (points != NULL) { + dx_free(points); + points = NULL; + } if (target != NULL) { SDL_DestroyTexture(target); target = NULL; @@ -398,6 +409,25 @@ int LZR_DrawPoint(int x, int y) return 0; } +int LZR_DrawPoints(int *x, int *y, int n) +{ + + if (n > (int)(config.display_width * config.display_height)) { + dx_log_error("%d > %u", n, + config.display_width * config.display_height); + return -1; + } + for (int i = 0; i < n; i++) { + points[i].x = x[i]; + points[i].y = y[i]; + } + if (SDL_RenderDrawPoints(renderer, points, n) < 0) { + dx_log_error("%s", SDL_GetError()); + return -1; + } + return 0; +} + int LZR_DrawLine(int x0, int y0, int x1, int y1) { if (SDL_RenderDrawLine(renderer, x0, y0, x1, y1) < 0) { @@ -54,6 +54,7 @@ int LZR_DrawEnd(void); int LZR_DrawSetColor(float r, float g, float b); int LZR_DrawClear(void); int LZR_DrawPoint(int x, int y); +int LZR_DrawPoints(int *x, int *y, int n); int LZR_DrawLine(int x0, int y0, int x1, int y1); int LZR_DrawRect(bool fill, int x, int y, int w, int h); int LZR_DrawCircle(bool fill, int x, int y, int radius); |