diff --git a/includes/text.h b/includes/text.h index fce7ff9..20438cf 100644 --- a/includes/text.h +++ b/includes/text.h @@ -9,7 +9,8 @@ TTF_Font *load_font(int quality); // Écrit du texte à une certaine position -void write_text(TTF_Font *font, GLfloat x, GLfloat y, char *text); +void write_text(TTF_Font *font, char *text, GLfloat *s, GLfloat *t, + Uint32 color); // Décharge la police void unload_font(TTF_Font *font); diff --git a/src/main.c b/src/main.c index fcbf30e..0e78d1a 100644 --- a/src/main.c +++ b/src/main.c @@ -29,12 +29,15 @@ void quit(void) { } void draw(void) { - gl4dpClearScreenWith(RGB(0, 0, 0)); job(); gl4dpUpdateScreen(NULL); } void job(void) { - write_text(font, 1.2, 10., "Othello"); + 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 index e66ce62..85877dd 100644 --- a/src/plateau.c +++ b/src/plateau.c @@ -8,7 +8,7 @@ Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) { table->height = height; table->color = color; - table->nb_columns = table->nb_row = 7; + table->nb_columns = table->nb_row = 8; GLuint wPas = table->width / table->nb_columns, hPas = table->height / table->nb_row, wMax = table->width - wPas, @@ -16,8 +16,8 @@ Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) { // 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) { + 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); @@ -26,8 +26,8 @@ Table *generate_table(GLuint width, GLuint height, Pos origin, Uint32 color) { 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) { + 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; diff --git a/src/text.c b/src/text.c index 1b6170f..9441fa1 100644 --- a/src/text.c +++ b/src/text.c @@ -1,6 +1,6 @@ #include "../includes/text.h" #include "SDL_ttf.h" -#include +#include TTF_Font *load_font(int quality) { if (TTF_Init() == -1) { @@ -11,14 +11,15 @@ TTF_Font *load_font(int quality) { return TTF_OpenFont("fonts/Hubot-Sans-Regular.ttf", quality); } -void write_text(TTF_Font *font, GLfloat x, GLfloat y, char *text) { +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)}); - SDL_Surface *surface = - TTF_RenderText_Solid(font, text, (SDL_Color){255, 255, 255, 255}); + gl4dpCopyFromSDLSurfaceWithTransforms(surface, s, t); - // TODO: Make scale depend of the text length - gl4dpCopyFromSDLSurfaceWithTransforms(surface, (GLfloat[2]){.3, -.1}, - (GLfloat[2]){x, y}); + SDL_FreeSurface(surface); } void unload_font(TTF_Font *font) { TTF_CloseFont(font); }