fix text display

This commit is contained in:
Mylloon 2022-11-15 14:17:54 +01:00
parent 44188694fb
commit 205760ea89
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 19 additions and 15 deletions

View file

@ -5,15 +5,14 @@
#include "plateau.h" #include "plateau.h"
TTF_Font *font = NULL; static TTF_Font *font = NULL;
SDL_Surface *surface = NULL; static SDL_Surface *surface = NULL;
SDL_Texture *texture = NULL;
// Charge la police d'écriture // Charge la police d'écriture
void load_font(int size_font); void load_font(int quality);
// Ecrit du texte à une certaine position // 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 // Décharge la police
void unload_font(void); void unload_font(void);

View file

@ -1,5 +1,7 @@
#include "../includes/main.h" #include "../includes/main.h"
int padding_title = 80;
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
assert(GL_TRUE == gl4duwCreateWindow(argc, argv, "Othello", 10, 10, 800, assert(GL_TRUE == gl4duwCreateWindow(argc, argv, "Othello", 10, 10, 800,
800, GL4DW_SHOWN)); 800, GL4DW_SHOWN));
@ -13,11 +15,7 @@ int main(int argc, char *argv[]) {
void init(void) { void init(void) {
gl4dpInitScreen(); gl4dpInitScreen();
load_font(25); load_font(60);
int padding_title = 80;
write_text((Pos){0, 0}, "salut");
table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title, table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title,
(Pos){0, 0}, RGB(255, 255, 255)); (Pos){0, 0}, RGB(255, 255, 255));
@ -36,4 +34,7 @@ void draw(void) {
gl4dpUpdateScreen(NULL); gl4dpUpdateScreen(NULL);
} }
void job(void) { draw_table(table); } void job(void) {
write_text(1.2, 10., "Othello");
draw_table(table);
}

View file

@ -1,18 +1,22 @@
#include "../includes/text.h" #include "../includes/text.h"
#include "SDL_ttf.h"
#include <GL4D/gl4dp.h>
void load_font(int size_font) { void load_font(int quality) {
if (TTF_Init() == -1) { if (TTF_Init() == -1) {
fprintf(stderr, "TTF_Init: %s\n", TTF_GetError()); fprintf(stderr, "TTF_Init: %s\n", TTF_GetError());
exit(EXIT_FAILURE); 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) { void write_text(GLfloat x, GLfloat y, char *text) {
printf("at %d,%d: %s\n", origin.x, origin.y, text);
surface = TTF_RenderText_Solid(font, text, (SDL_Color){255, 255, 255, 255}); 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); } void unload_font(void) { TTF_CloseFont(font); }