From 205760ea89540e2355f8f77bba802411badaf3fe Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 15 Nov 2022 14:17:54 +0100 Subject: [PATCH] fix text display --- includes/text.h | 9 ++++----- src/main.c | 13 +++++++------ src/text.c | 12 ++++++++---- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/includes/text.h b/includes/text.h index cb54cf5..b94c199 100644 --- a/includes/text.h +++ b/includes/text.h @@ -5,15 +5,14 @@ #include "plateau.h" -TTF_Font *font = NULL; -SDL_Surface *surface = NULL; -SDL_Texture *texture = NULL; +static TTF_Font *font = NULL; +static SDL_Surface *surface = NULL; // Charge la police d'écriture -void load_font(int size_font); +void load_font(int quality); // Ecrit du texte à une certaine position -void write_text(Pos origin, char *text); +void write_text(GLfloat x, GLfloat y, char *text); // Décharge la police void unload_font(void); diff --git a/src/main.c b/src/main.c index 91a641a..511b2fa 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +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)); @@ -13,11 +15,7 @@ int main(int argc, char *argv[]) { void init(void) { gl4dpInitScreen(); - load_font(25); - - int padding_title = 80; - - write_text((Pos){0, 0}, "salut"); + load_font(60); table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title, (Pos){0, 0}, RGB(255, 255, 255)); @@ -36,4 +34,7 @@ void draw(void) { gl4dpUpdateScreen(NULL); } -void job(void) { draw_table(table); } +void job(void) { + write_text(1.2, 10., "Othello"); + draw_table(table); +} diff --git a/src/text.c b/src/text.c index 5aa1355..c3348d9 100644 --- a/src/text.c +++ b/src/text.c @@ -1,18 +1,22 @@ #include "../includes/text.h" +#include "SDL_ttf.h" +#include -void load_font(int size_font) { +void load_font(int quality) { if (TTF_Init() == -1) { fprintf(stderr, "TTF_Init: %s\n", TTF_GetError()); exit(EXIT_FAILURE); } - font = TTF_OpenFont("fonts/Hubot-Sans-Regular.ttf", size_font); + font = TTF_OpenFont("fonts/Hubot-Sans-Regular.ttf", quality); } -void write_text(Pos origin, char *text) { - printf("at %d,%d: %s\n", origin.x, origin.y, text); +void write_text(GLfloat x, GLfloat y, char *text) { surface = TTF_RenderText_Solid(font, text, (SDL_Color){255, 255, 255, 255}); + + gl4dpCopyFromSDLSurfaceWithTransforms(surface, (GLfloat[2]){.3, -.1}, + (GLfloat[2]){x, y}); } void unload_font(void) { TTF_CloseFont(font); }