From 252d228cb6b94172dd0cff9ef0076111d6d05e45 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 15 Nov 2022 13:02:58 +0100 Subject: [PATCH] * add padding for title * clear screen with rgb color * better detection of endloop * assert if malloc 0 --- src/main.c | 9 +++++---- src/plateau.c | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 2765aad..a2dcfd6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,4 @@ #include "../includes/main.h" -#include int main(int argc, char *argv[]) { assert(GL_TRUE == gl4duwCreateWindow(argc, argv, "Othello", 10, 10, 800, @@ -15,8 +14,10 @@ int main(int argc, char *argv[]) { void init(void) { gl4dpInitScreen(); - table = generate_table(gl4dpGetWidth(), gl4dpGetHeight(), (Pos){0, 0}, - RGB(255, 255, 255)); + int padding_title = 80; + + table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title, + (Pos){0, 0}, RGB(255, 255, 255)); atexit(quit); } @@ -24,7 +25,7 @@ void init(void) { void quit(void) { free_table(table); } void draw(void) { - gl4dpClearScreen(); + gl4dpClearScreenWith(RGB(0, 0, 0)); job(); gl4dpUpdateScreen(NULL); } diff --git a/src/plateau.c b/src/plateau.c index c170eb1..8968b04 100644 --- a/src/plateau.c +++ b/src/plateau.c @@ -21,6 +21,7 @@ Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) { for (GLuint j = hPas; j < hMax; j += hPas, space_needed += 4) { } } + assert(space_needed != 0); table->lines = malloc(space_needed * sizeof(int)); assert(table->lines != NULL); @@ -39,7 +40,6 @@ Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) { *(tmp + 2) = i; *(tmp + 3) = table->height; } - *(tmp) = -1; return table; } @@ -52,7 +52,7 @@ void free_table(Table *table) { void draw_table(Table *table) { gl4dpSetColor(table->color); - for (int *ptr = table->lines; *(ptr) != -1; ptr += 4) { + for (int *ptr = table->lines; *ptr; ptr += 4) { gl4dpLine(*ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3)); } }