From 8166d3fa39314dae1bf31e72269a0adff238fdf9 Mon Sep 17 00:00:00 2001 From: herbglitch Date: Tue, 11 Feb 2025 00:57:39 -0700 Subject: [PATCH] updated sdl2 to use sdl2_gfx --- cmake/archeus_sdl2.cmake | 5 ++++ include/arc/math/circle.h | 12 +++++++++ include/arc/math/point.h | 5 ++++ packages/graphics/sdl/circle.c | 45 +++------------------------------- 4 files changed, 26 insertions(+), 41 deletions(-) diff --git a/cmake/archeus_sdl2.cmake b/cmake/archeus_sdl2.cmake index f6d32eb..1e8e380 100644 --- a/cmake/archeus_sdl2.cmake +++ b/cmake/archeus_sdl2.cmake @@ -63,17 +63,22 @@ function(sdl2_check_and_init_needed _ARCHEUS_SOURCES _ARCHEUS_INCLUDE_DIRECTORIE find_package(SDL2_image REQUIRED) find_package(SDL2_ttf REQUIRED) + find_package(PkgConfig REQUIRED) + pkg_check_modules(SDL2_GFX REQUIRED SDL2_gfx) + list(APPEND ${_ARCHEUS_SOURCES} ${ARCHEUS_SDL2_GRAPHICS_SOURCES}) #add to include directories list(APPEND ${_ARCHEUS_INCLUDE_DIRECTORIES} PRIVATE ${SDL2IMAGE_INCLUDE_DIRS} + PRIVATE ${SDL2_GFX_INCLUDE_DIRS} ) #add to link libraries list(APPEND ${_ARCHEUS_LINK_LIBRARIES} PUBLIC SDL2_image::SDL2_image PUBLIC SDL2_ttf::SDL2_ttf + PUBLIC ${SDL2_GFX_LIBRARIES} ) endif() diff --git a/include/arc/math/circle.h b/include/arc/math/circle.h index da3e63b..60d9acb 100644 --- a/include/arc/math/circle.h +++ b/include/arc/math/circle.h @@ -13,6 +13,18 @@ typedef struct ARC_Circle { int32_t r; } ARC_Circle; +typedef struct ARC_FCircle { + float x; + float y; + float r; +} ARC_FCircle; + +typedef struct ARC_DCircle { + double x; + double y; + double r; +} ARC_DCircle; + #ifdef __cplusplus } #endif diff --git a/include/arc/math/point.h b/include/arc/math/point.h index 953c08f..2af564b 100644 --- a/include/arc/math/point.h +++ b/include/arc/math/point.h @@ -22,6 +22,11 @@ typedef struct ARC_FPoint { float y; } ARC_FPoint; +typedef struct ARC_DPoint { + double x; + double y; +} ARC_DPoint; + ARC_FPoint ARC_FPoint_Lerp(ARC_FPoint *start, ARC_FPoint *end, float t); #ifdef __cplusplus diff --git a/packages/graphics/sdl/circle.c b/packages/graphics/sdl/circle.c index 8c208a3..c4e4ca6 100644 --- a/packages/graphics/sdl/circle.c +++ b/packages/graphics/sdl/circle.c @@ -1,49 +1,12 @@ #include "arc/graphics/circle.h" -#include "renderer.h" -#include +#include //Modified from https://stackoverflow.com/questions/38334081/how-to-draw-circles-arcs-and-vector-graphics-in-sdl void ARC_Circle_Render(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){ - SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a); - - int32_t diameter = (circle->r * 2); - - int32_t x = (circle->r - 1); - int32_t y = 0; - int32_t tx = 1; - int32_t ty = 1; - int32_t error = (tx - diameter); - - while(x >= y){ - // Each of the following renders an octant of the circle - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y - y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + x, circle->y + y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y - y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - x, circle->y + y); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y - x); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x + y, circle->y + x); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y - x); - SDL_RenderDrawPoint((SDL_Renderer *)renderer, circle->x - y, circle->y + x); - - if(error <= 0){ - ++y; - error += ty; - ty += 2; - } - - if(error > 0){ - --x; - tx += 2; - error += (tx - diameter); - } - } + circleRGBA((SDL_Renderer *)renderer, (Sint16)circle->x, (Sint16)circle->y, (Sint16)circle->r, (Uint8)color->r, (Uint8)color->g, (Uint8)color->b, (Uint8)color->a); } //TODO: very temp void ARC_Circle_RenderFill(ARC_Circle *circle, ARC_Renderer *renderer, ARC_Color *color){ - ARC_Circle temp = *circle; - - for(; temp.r; temp.r--){ - ARC_Circle_Render(&temp, renderer, color); - } -} \ No newline at end of file + filledCircleRGBA((SDL_Renderer *)renderer, (Sint16)circle->x, (Sint16)circle->y, (Sint16)circle->r, (Uint8)color->r, (Uint8)color->g, (Uint8)color->b, (Uint8)color->a); +}