updated sdl2 to use sdl2_gfx
This commit is contained in:
parent
66ff7877cb
commit
8166d3fa39
4 changed files with 26 additions and 41 deletions
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,49 +1,12 @@
|
|||
#include "arc/graphics/circle.h"
|
||||
#include "renderer.h"
|
||||
#include <stdlib.h>
|
||||
#include <SDL2_gfxPrimitives.h>
|
||||
|
||||
//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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue