text related
This commit is contained in:
parent
3f324d671a
commit
44188694fb
3 changed files with 46 additions and 1 deletions
21
includes/text.h
Normal file
21
includes/text.h
Normal 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
|
|
@ -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
18
src/text.c
Normal 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); }
|
Reference in a new issue