text related

This commit is contained in:
Mylloon 2022-11-15 13:49:40 +01:00
parent 3f324d671a
commit 44188694fb
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 46 additions and 1 deletions

21
includes/text.h Normal file
View file

@ -0,0 +1,21 @@
#ifndef OTHELLO_TEXT_H
#define OTHELLO_TEXT_H 1
#include <SDL_ttf.h>
#include "plateau.h"
TTF_Font *font = NULL;
SDL_Surface *surface = NULL;
SDL_Texture *texture = NULL;
// Charge la police d'écriture
void load_font(int size_font);
// Ecrit du texte à une certaine position
void write_text(Pos origin, char *text);
// Décharge la police
void unload_font(void);
#endif

View file

@ -13,16 +13,22 @@ int main(int argc, char *argv[]) {
void init(void) {
gl4dpInitScreen();
load_font(25);
int padding_title = 80;
write_text((Pos){0, 0}, "salut");
table = generate_table(gl4dpGetWidth(), gl4dpGetHeight() - padding_title,
(Pos){0, 0}, RGB(255, 255, 255));
atexit(quit);
}
void quit(void) { free_table(table); }
void quit(void) {
free_table(table);
unload_font();
}
void draw(void) {
gl4dpClearScreenWith(RGB(0, 0, 0));

18
src/text.c Normal file
View file

@ -0,0 +1,18 @@
#include "../includes/text.h"
void load_font(int size_font) {
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);
}
void write_text(Pos origin, 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});
}
void unload_font(void) { TTF_CloseFont(font); }