diff options
author | 2025-05-20 19:53:01 +0200 | |
---|---|---|
committer | 2025-05-20 19:53:01 +0200 | |
commit | 7f2339edd8449d79de2dc22fdfaa40658c5a201f (patch) | |
tree | e477516a3f2eac6bd252486833d10148163a262f | |
parent | 6613969cd6511acb4f7faf6ab99caa9ee8838a2e (diff) | |
download | tris-7f2339edd8449d79de2dc22fdfaa40658c5a201f.tar.gz tris-7f2339edd8449d79de2dc22fdfaa40658c5a201f.zip |
Add function to draw circle
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | src/main/engine/engine.c | 28 | ||||
-rw-r--r-- | src/main/engine/engine.h | 1 |
4 files changed, 31 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 119a240..006cbf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,4 +40,4 @@ add_executable(tris src/main/engine/ui/types.h src/main/engine/types.h) -target_link_libraries(tris PRIVATE X11 GL GLX) +target_link_libraries(tris PRIVATE X11 GL GLX m) @@ -30,6 +30,7 @@ CFLAGS != pkg-config --cflags ${LIBS} LFLAGS != pkg-config --libs ${LIBS} CFLAGS += -DX11 +LFLAGS += -lm ${PROG}: ${OBJ} ${CC} ${OBJ} -o $@ ${LFLAGS} diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c index d66c242..048c618 100644 --- a/src/main/engine/engine.c +++ b/src/main/engine/engine.c @@ -21,6 +21,7 @@ #include <stdlib.h> #include <time.h> #include <GL/gl.h> +#include <math.h> #include "engine.h" #include "../util.h" #include "ui/ui.h" @@ -157,6 +158,32 @@ draw_lines() } static void +render_circle(Circle *circle) +{ + for (int i = 0; i < circle->num_segments; i++) { + float theta = 2.0f * M_PI * i / circle->num_segments; + float x = circle->r * cosf(theta); + float y = circle->r * sinf(theta); + glVertex2f(circle->cx + x, circle->cy + y); + } +} + +static void +draw_circles() +{ + if (engine == NULL || engine->circles == NULL || engine->circles->size <= 0) return; + glBegin(GL_LINE_LOOP); + + list_node_t *current = engine->circles->head; + do { + render_circle(current->data); + current = current->next; + } while (current != NULL); + + glEnd(); +} + +static void draw_frames() { glClearColor(0.0f, 0.0f, 0.2f, 1.0f); @@ -166,6 +193,7 @@ draw_frames() glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); draw_lines(); + draw_circles(); engine_calculate_fps(); } diff --git a/src/main/engine/engine.h b/src/main/engine/engine.h index 101a9a4..b28a3c5 100644 --- a/src/main/engine/engine.h +++ b/src/main/engine/engine.h @@ -25,6 +25,7 @@ enum EngineInput { }; void engine_init(int width, int height); +void engine_draw_circle(float cx, float cy, float r, int num_segments, int outline); void engine_draw_line(float x1, float y1, float x2, float y2); void engine_loop(void); void engine_input(void (*f_input)(int engine_input)); |