From cbc804efd260085065437f4e72b6467e172f66d0 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 15 Nov 2022 15:09:28 +0100 Subject: [PATCH] remove font warnings --- includes/main.h | 2 ++ includes/text.h | 11 ++++------- src/main.c | 6 +++--- src/text.c | 11 ++++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/includes/main.h b/includes/main.h index 4d46f0d..a331d69 100644 --- a/includes/main.h +++ b/includes/main.h @@ -3,11 +3,13 @@ #include #include +#include #include "text.h" // Plateau static Table *table = NULL; +static TTF_Font *font = NULL; // Initialise le programme static void init(void); diff --git a/includes/text.h b/includes/text.h index b94c199..fce7ff9 100644 --- a/includes/text.h +++ b/includes/text.h @@ -5,16 +5,13 @@ #include "plateau.h" -static TTF_Font *font = NULL; -static SDL_Surface *surface = NULL; - // Charge la police d'écriture -void load_font(int quality); +TTF_Font *load_font(int quality); -// Ecrit du texte à une certaine position -void write_text(GLfloat x, GLfloat y, char *text); +// Écrit du texte à une certaine position +void write_text(TTF_Font *font, GLfloat x, GLfloat y, char *text); // Décharge la police -void unload_font(void); +void unload_font(TTF_Font *font); #endif diff --git a/src/main.c b/src/main.c index 511b2fa..fcbf30e 100644 --- a/src/main.c +++ b/src/main.c @@ -15,7 +15,7 @@ int main(int argc, char *argv[]) { void init(void) { gl4dpInitScreen(); - load_font(60); + font = load_font(60); table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title, (Pos){0, 0}, RGB(255, 255, 255)); @@ -25,7 +25,7 @@ void init(void) { void quit(void) { free_table(table); - unload_font(); + unload_font(font); } void draw(void) { @@ -35,6 +35,6 @@ void draw(void) { } void job(void) { - write_text(1.2, 10., "Othello"); + write_text(font, 1.2, 10., "Othello"); draw_table(table); } diff --git a/src/text.c b/src/text.c index ea3d1be..1b6170f 100644 --- a/src/text.c +++ b/src/text.c @@ -2,22 +2,23 @@ #include "SDL_ttf.h" #include -void load_font(int quality) { +TTF_Font *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", quality); + return TTF_OpenFont("fonts/Hubot-Sans-Regular.ttf", quality); } -void write_text(GLfloat x, GLfloat y, char *text) { +void write_text(TTF_Font *font, GLfloat x, GLfloat y, char *text) { - surface = TTF_RenderText_Solid(font, text, (SDL_Color){255, 255, 255, 255}); + SDL_Surface *surface = + TTF_RenderText_Solid(font, text, (SDL_Color){255, 255, 255, 255}); // TODO: Make scale depend of the text length gl4dpCopyFromSDLSurfaceWithTransforms(surface, (GLfloat[2]){.3, -.1}, (GLfloat[2]){x, y}); } -void unload_font(void) { TTF_CloseFont(font); } +void unload_font(TTF_Font *font) { TTF_CloseFont(font); }