diff options
author | kdx <kikoodx@paranoici.org> | 2022-09-08 03:03:33 +0200 |
---|---|---|
committer | kdx <kikoodx@paranoici.org> | 2022-09-08 03:03:33 +0200 |
commit | 9d007dc6a46994f7095f396ff216b520d589c8a7 (patch) | |
tree | e257d879c546c7eab228ee5a6be4f24fbb3e55d7 | |
parent | 1151afe6323bcfb287d9f4aa45848436badf69ea (diff) | |
download | lzr-9d007dc6a46994f7095f396ff216b520d589c8a7.tar.gz |
draw circle
-rw-r--r-- | Tupfile | 2 | ||||
-rw-r--r-- | demo.c | 1 | ||||
-rw-r--r-- | lzr.c | 24 | ||||
-rw-r--r-- | lzr.h | 1 |
4 files changed, 19 insertions, 9 deletions
@@ -1,5 +1,5 @@ CFLAGS = -Wall -Wextra -std=c99 -pedantic `sdl2-config --cflags` -LDFLAGS = -ldx `sdl2-config --libs` +LDFLAGS = -ldx `sdl2-config --libs` -lSDL2_gfx .gitignore : foreach *.c |> gcc $(CFLAGS) -c -o %o %f |> %B.o @@ -48,6 +48,7 @@ int main(void) const float shade = 0.9 * (0.5f + darkness); LZR_DrawSetColor(shade, shade, 0.0f); LZR_DrawImageEx(0, x, y, stg); + LZR_DrawCircle(false, x, y, 100); LZR_DrawEnd(); } LZR_Quit(); @@ -1,7 +1,6 @@ #include "lzr.h" #include <SDL2/SDL.h> -#include <SDL2/SDL_error.h> -#include <SDL2/SDL_render.h> +#include <SDL2/SDL2_gfxPrimitives.h> #include <dx/log.h> #include <dx/mem.h> #include <dx/str.h> @@ -9,6 +8,8 @@ #include <stdint.h> #include <string.h> +#define UNPACKED_COLOR color[0], color[1], color[2] + static LZR_Config config = {0}; static char *basepath = NULL; static SDL_Window *window = NULL; @@ -315,6 +316,16 @@ int LZR_DrawLine(int x0, int y0, int x1, int y1) return 0; } +int LZR_DrawCircle(bool fill, int x, int y, int radius) +{ + if ((fill ? filledCircleRGBA : circleRGBA)(renderer, x, y, radius, + UNPACKED_COLOR, 255) < 0) { + dx_log_error("%s", SDL_GetError()); + return -1; + } + return 0; +} + int LZR_DrawImage(int id, int x, int y) { if (id < 0) { @@ -325,8 +336,7 @@ int LZR_DrawImage(int id, int x, int y) dx_log_error("no image with id %d", id); return -1; } - if (SDL_SetTextureColorMod(images[id].tex, color[0], color[1], - color[2]) < 0) { + if (SDL_SetTextureColorMod(images[id].tex, UNPACKED_COLOR) < 0) { dx_log_error("%s", SDL_GetError()); return -1; } @@ -375,8 +385,7 @@ int LZR_DrawImageEx(int id, int x, int y, LZR_ImageDrawSettings stg) src.h = images[id].height - stg.iy; dst.h = images[id].height - stg.iy; } - if (SDL_SetTextureColorMod(images[id].tex, color[0], color[1], - color[2]) < 0) { + if (SDL_SetTextureColorMod(images[id].tex, UNPACKED_COLOR) < 0) { dx_log_error("%s", SDL_GetError()); return -1; } @@ -410,8 +419,7 @@ int LZR_DrawTile(int id, int tile, int x, int y) dx_log_error("tile exceeds boundaries"); return -1; } - if (SDL_SetTextureColorMod(images[id].tex, color[0], color[1], - color[2]) < 0) { + if (SDL_SetTextureColorMod(images[id].tex, UNPACKED_COLOR) < 0) { dx_log_error("%s", SDL_GetError()); return -1; } @@ -53,6 +53,7 @@ int LZR_DrawClear(void); int LZR_DrawPoint(int x, int y); 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); int LZR_DrawImage(int id, int x, int y); int LZR_DrawImageEx(int id, int x, int y, LZR_ImageDrawSettings stg); int LZR_DrawTile(int id, int tile, int x, int y); |