diff options
Diffstat (limited to 'src/main/engine/engine.c')
-rw-r--r-- | src/main/engine/engine.c | 68 |
1 files changed, 58 insertions, 10 deletions
diff --git a/src/main/engine/engine.c b/src/main/engine/engine.c index e619dc7..8db206a 100644 --- a/src/main/engine/engine.c +++ b/src/main/engine/engine.c @@ -18,10 +18,12 @@ */ #include <stdio.h> +#include <stdlib.h> #include <time.h> #include <GL/gl.h> -#include "../ui/ui.h" #include "engine.h" +#include "../ui/ui.h" +#include "../util/list.h" #ifdef X11 #include <X11/Xlib.h> @@ -34,6 +36,12 @@ static float ystep; static int width; static int height; +static list_t *lines = NULL; + +typedef struct Line { + int x1, y1, x2, y2; +} Line; + typedef struct Engine { void (*draw_frame)(); } Engine; @@ -57,16 +65,29 @@ engine_init(int w, int h) xstep = RANGE_GL / (float) w; ystep = RANGE_GL / (float) h; + + lines = list_create(); +} + +static Line * +engine_new_line(int x1, int y1, int x2, int y2) +{ + Line *line = malloc(sizeof(Line)); + line->x1 = x1; + line->y1 = y1; + line->x2 = x2; + line->y2 = y2; + + return line; } void engine_draw_line(int x1, int y1, int x2, int y2) { - float _x1 = x1 * xstep - 1; float _y1 = (height - y1) * ystep - 1; - float _x2 = x2 * xstep - 1; float _y2 = (height - y2) * ystep - 1; - - glVertex2f(_x1, _y1); - glVertex2f(_x2, _y2); + if (lines != NULL) { + Line *line = engine_new_line(x1, y1, x2, y2); + list_add(lines, line); + } } static void @@ -83,6 +104,34 @@ engine_calculate_fps() } static void +render_line(Line *line) +{ + float _x1 = line->x1 * xstep - 1; float _y1 = (height - line->y1) * ystep - 1; + float _x2 = line->x2 * xstep - 1; float _y2 = (height - line->y2) * ystep - 1; + + glVertex2f(_x1, _y1); + glVertex2f(_x2, _y2); +} + +static void +draw_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 { + render_line((Line *) current->data); + current = current->next; + } while (current != NULL); + + glEnd(); +} + +static void draw_frames() { glClearColor(0.0f, 0.0f, 0.2f, 1.0f); @@ -91,15 +140,14 @@ draw_frames() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - engine.draw_frame(); + draw_lines(); + engine_calculate_fps(); } void -engine_loop(void (*draw_frame)()) +engine_loop(void) { - engine.draw_frame = draw_frame; - ui_set_loop_listener(draw_frames); /* FPS calculation */ |