diff --git a/.gitignore b/.gitignore index e3e255e..594c737 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,2 @@ -compile_flags.txt - *.o othello - -fonts/ diff --git a/Makefile b/Makefile index 0deff6e..e202b11 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ CC = gcc -CFLAGS = -I. -I/usr/include/SDL2 -std=c11 -O3 +CFLAGS = -std=c11 -O3 RM = rm -LDFLAGS = -lm -lGL -lGL4Dummies -lSDL2 -lSDL2_ttf SOURCES = $(wildcard src/*.c) OBJECTS = $(patsubst %.c,%.c.o,$(notdir $(SOURCES))) @@ -15,7 +14,6 @@ main: compilation dev: CFLAGS += -Wall -Wextra -Wshadow -Wcast-align -Wstrict-prototypes dev: CFLAGS += -fanalyzer -fsanitize=undefined -pedantic -g -dev: LDFLAGS += -fsanitize=undefined dev: compilation compilation: $(OBJECTS) diff --git a/fonts/.gitkeep b/fonts/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/includes/main.h b/includes/main.h index a331d69..8fc5d37 100644 --- a/includes/main.h +++ b/includes/main.h @@ -1,26 +1,7 @@ #ifndef OTHELLO_MAIN_H #define OTHELLO_MAIN_H 1 -#include -#include -#include - -#include "text.h" - -// Plateau -static Table *table = NULL; -static TTF_Font *font = NULL; - -// Initialise le programme -static void init(void); - -// Série d'évènement pendant chaque rendu de frame -static void job(void); - -// Dessine dans la fenêtre -static void draw(void); - -// Quitte le programme -static void quit(void); +#include +#include #endif diff --git a/includes/plateau.h b/includes/plateau.h deleted file mode 100644 index 0fcd0f9..0000000 --- a/includes/plateau.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef OTHELLO_PLATEAU_H -#define OTHELLO_PLATEAU_H 1 - -#include -#include - -#include -#include - -// Position d'un point x, y -struct pos { - GLuint x, y; -}; -typedef struct pos Pos; - -// Plateau -struct table { - GLuint width; - GLuint height; - - int nb_row; - int nb_columns; - - // TODO: Use Pos ? add center to the struct? - // Need malloc for each struct - int *lines; - - Uint32 color; -}; -typedef struct table Table; - -// Génère une structure de plateau -Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color); - -// Libère le plateau en mémoire -void free_table(Table *table); - -/* Dessine le plateau */ -void draw_table(Table *); - -#endif diff --git a/includes/text.h b/includes/text.h deleted file mode 100644 index 20438cf..0000000 --- a/includes/text.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef OTHELLO_TEXT_H -#define OTHELLO_TEXT_H 1 - -#include - -#include "plateau.h" - -// Charge la police d'écriture -TTF_Font *load_font(int quality); - -// Écrit du texte à une certaine position -void write_text(TTF_Font *font, char *text, GLfloat *s, GLfloat *t, - Uint32 color); - -// Décharge la police -void unload_font(TTF_Font *font); - -#endif diff --git a/src/main.c b/src/main.c index 0e78d1a..bd8cf72 100644 --- a/src/main.c +++ b/src/main.c @@ -1,43 +1,7 @@ #include "../includes/main.h" -int padding_title = 80; - int main(int argc, char *argv[]) { - assert(GL_TRUE == gl4duwCreateWindow(argc, argv, "Othello", 10, 10, 800, - 800, GL4DW_SHOWN)); - init(); - - gl4duwDisplayFunc(draw); - gl4duwMainLoop(); + printf("Othello\n"); return EXIT_SUCCESS; } - -void init(void) { - gl4dpInitScreen(); - font = load_font(60); - - table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title, - (Pos){0, 0}, RGB(255, 255, 255)); - - atexit(quit); -} - -void quit(void) { - free_table(table); - unload_font(font); -} - -void draw(void) { - job(); - gl4dpUpdateScreen(NULL); -} - -void job(void) { - char title[21]; - sprintf(title, "Othello - tour des %c", 'B'); - write_text(font, title, (GLfloat[2]){.6, -.1}, (GLfloat[2]){.3, 10.}, - RGB(255, 255, 255)); - - draw_table(table); -} diff --git a/src/plateau.c b/src/plateau.c deleted file mode 100644 index 85877dd..0000000 --- a/src/plateau.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "../includes/plateau.h" - -Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) { - Table *table = malloc(sizeof(Table)); - assert(table != NULL); - - table->width = width; - table->height = height; - table->color = color; - - table->nb_columns = table->nb_row = 8; - - GLuint wPas = table->width / table->nb_columns, - hPas = table->height / table->nb_row, wMax = table->width - wPas, - hMax = table->height - hPas; - - // Calcul l'espace neccessaire - int space_needed = 1; - for (GLuint i = wPas; i <= wMax; i += wPas, space_needed += 4) { - 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); - - int *tmp = table->lines; - for (GLuint i = wPas; i <= wMax; i += wPas, tmp += 4) { - for (GLuint j = hPas; j <= hMax; j += hPas, tmp += 4) { - *tmp = table->width; - *(tmp + 1) = j; - *(tmp + 2) = origin.x; - *(tmp + 3) = j; - } - - *tmp = i; - *(tmp + 1) = origin.y; - *(tmp + 2) = i; - *(tmp + 3) = table->height; - } - *tmp = -1; - - return table; -} - -void free_table(Table *table) { - free(table->lines); - free(table); -} - -void draw_table(Table *table) { - gl4dpSetColor(table->color); - - for (int *ptr = table->lines; *ptr != -1; ptr += 4) { - gl4dpLine(*ptr, *(ptr + 1), *(ptr + 2), *(ptr + 3)); - } -} diff --git a/src/text.c b/src/text.c deleted file mode 100644 index 9441fa1..0000000 --- a/src/text.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "../includes/text.h" -#include "SDL_ttf.h" -#include - -TTF_Font *load_font(int quality) { - if (TTF_Init() == -1) { - fprintf(stderr, "TTF_Init: %s\n", TTF_GetError()); - exit(EXIT_FAILURE); - } - - return TTF_OpenFont("fonts/Hubot-Sans-Regular.ttf", quality); -} - -void write_text(TTF_Font *font, char *text, GLfloat *s, GLfloat *t, - Uint32 color) { - SDL_Surface *surface = TTF_RenderText_Solid( - font, text, - (SDL_Color){RED(color), GREEN(color), BLUE(color), ALPHA(color)}); - - gl4dpCopyFromSDLSurfaceWithTransforms(surface, s, t); - - SDL_FreeSurface(surface); -} - -void unload_font(TTF_Font *font) { TTF_CloseFont(font); }