diff options
Diffstat (limited to 'src/main/engine')
-rw-r--r-- | src/main/engine/engine.c | 54 | ||||
-rw-r--r-- | src/main/engine/engine.h | 3 | ||||
-rw-r--r-- | src/main/engine/shape/circle.h | 3 | ||||
-rw-r--r-- | src/main/engine/shape/line.c | 69 | ||||
-rw-r--r-- | src/main/engine/shape/line.h | 35 |
5 files changed, 108 insertions, 56 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c index a555a89..495b960 100644 --- a/src/main/engine/engine.c +++ b/src/main/engine/engine.c @@ -21,12 +21,10 @@ #include <stdlib.h> #include <time.h> #include <GL/gl.h> -#include <math.h> #include <log.h> #include "engine.h" #include "ui/ui.h" #include "../util/list.h" -#include "shape/circle.h" #ifdef X11 #include <X11/Xlib.h> @@ -43,10 +41,6 @@ init_log(void) _log = log_create("Engine"); } -typedef struct Line { - float x1, y1, x2, y2; -} Line; - static Engine *engine; /* FPS */ @@ -73,7 +67,6 @@ engine_new(int w, int h) log_error(_log, "Error allocating memory for engine"); exit(EXIT_FAILURE); } - engine->lines = list_create(); engine->ui = ui_new(w, h); engine_set_rendering_background(engine, 0.0f, 0.0f, 0.2f, 1.0f); @@ -87,27 +80,6 @@ engine_set_window_title(Engine *engine, const char *title) ui_set_title(engine->ui, title); } -static Line * -engine_new_line(float x1, float y1, float x2, float y2) -{ - Line *line = malloc(sizeof(Line)); - line->x1 = x1; - line->y1 = y1; - line->x2 = x2; - line->y2 = y2; - - return line; -} - -void -engine_draw_line(float x1, float y1, float x2, float y2) -{ - if (engine->lines != NULL) { - Line *line = engine_new_line(x1, y1, x2, y2); - list_add(engine->lines, line); - } -} - static void engine_calculate_fps() { @@ -124,31 +96,6 @@ engine_calculate_fps() } static void -render_line(Line *line) -{ - glVertex2f(line->x1, line->y1); - glVertex2f(line->x2, line->y2); -} - -static void -draw_lines() -{ - if (engine->lines == NULL || engine->lines->size <= 0) return; - - glLineWidth(5.0f); - glBegin(GL_LINES); - glColor3f(1.0f, 1.0f, 0.0f); /* Yellow */ - - list_node_t *current = engine->lines->head; - do { - render_line(current->data); - current = current->next; - } while (current != NULL); - - glEnd(); -} - -static void draw_frames(void *data) { if (data == NULL) return; @@ -162,7 +109,6 @@ draw_frames(void *data) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - draw_lines(); engine->draw_frame_listener->draw_frames(engine->draw_frame_listener->data); engine_calculate_fps(); diff --git a/src/main/engine/engine.h b/src/main/engine/engine.h index 24dbe61..1d36632 100644 --- a/src/main/engine/engine.h +++ b/src/main/engine/engine.h @@ -25,6 +25,7 @@ #include "domain/color.h" #include "shape/circle.h" +#include "shape/line.h" enum EngineInput { ENGINE_MOUSE_PRESSED = 4 @@ -38,7 +39,6 @@ typedef struct DrawFrameListener { typedef struct { UI *ui; list_t *circles1; - list_t *lines; float ortho_left, ortho_right, ortho_top, ortho_bottom; Color *rendering_background; /* Listeners */ @@ -50,7 +50,6 @@ void engine_set_rendering_background(Engine *engine, float r, float g, float void engine_set_rendering_background_c(Engine *engine, Color *color); void engine_set_window_title(Engine *engine, const char *title); void engine_set_rendering_listener(Engine *engine, void (*draw_frames)(void *data), void *data); -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)); void engine_set_mouse_button_listener(void (*event)(float x, float y, void *data), void *data); diff --git a/src/main/engine/shape/circle.h b/src/main/engine/shape/circle.h index 72e69e1..67c3a46 100644 --- a/src/main/engine/shape/circle.h +++ b/src/main/engine/shape/circle.h @@ -20,12 +20,15 @@ #ifndef __CIRCLE_H__ #define __CIRCLE_H__ +#include "../domain/color.h" + typedef struct { int outline; float cx; float cy; float r; int num_segments; + Color *color; } Circle; Circle *engine_circle_new(float cx, float cy, float r, int num_segments, int outline); diff --git a/src/main/engine/shape/line.c b/src/main/engine/shape/line.c new file mode 100644 index 0000000..7c0bc18 --- /dev/null +++ b/src/main/engine/shape/line.c @@ -0,0 +1,69 @@ +/*- + * Copyright (C) 2025 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it> + * + * This file is part of Tris Game. + * + * Tris Game is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tris Game is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tris Game. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <stdlib.h> +#include <GL/gl.h> +#include "line.h" + +Line * +engine_line_new(float x1, float y1, float x2, float y2) +{ + Line *line = malloc(sizeof(Line)); + line->x1 = x1; + line->y1 = y1; + line->x2 = x2; + line->y2 = y2; + + return line; +} + +void +engine_render_line(Line *line) +{ + glLineWidth(5.0f); + glBegin(GL_LINES); + glColor3f(1.0f, 1.0f, 0.0f); /* Yellow */ + + glVertex2f(line->x1, line->y1); + glVertex2f(line->x2, line->y2); + + glEnd(); +} + +void +engine_render_lines(list_t *lines) +{ + if (lines == NULL || lines->size <= 0) return; + + glLineWidth(5.0f); + glBegin(GL_LINES); + glColor3f(1.0f, 1.0f, 0.0f); /* Yellow */ + + list_node_t *current = lines->head; + do { + Line *line = current->data; + + glVertex2f(line->x1, line->y1); + glVertex2f(line->x2, line->y2); + + current = current->next; + } while (current != NULL); + + glEnd(); +} diff --git a/src/main/engine/shape/line.h b/src/main/engine/shape/line.h new file mode 100644 index 0000000..c1a933d --- /dev/null +++ b/src/main/engine/shape/line.h @@ -0,0 +1,35 @@ +/*- + * Copyright (C) 2025 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it> + * + * This file is part of Tris Game. + * + * Tris Game is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tris Game is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tris Game. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef __ENGINE_LINE_H__ +#define __ENGINE_LINE_H__ + +#include "../domain/color.h" +#include "../../util/list.h" + +typedef struct Line { + float x1, y1, x2, y2; + Color *color; +} Line; + +Line *engine_line_new(float x1, float y1, float x2, float y2); +void engine_render_line(Line *line); +void engine_render_lines(list_t *lines); + +#endif /* __ENGINE_LINE_H__ */ |