remove font warnings
This commit is contained in:
parent
9b1046667d
commit
cbc804efd2
4 changed files with 15 additions and 15 deletions
|
@ -3,11 +3,13 @@
|
||||||
|
|
||||||
#include <GL4D/gl4dp.h>
|
#include <GL4D/gl4dp.h>
|
||||||
#include <GL4D/gl4duw_SDL2.h>
|
#include <GL4D/gl4duw_SDL2.h>
|
||||||
|
#include <SDL_ttf.h>
|
||||||
|
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
|
|
||||||
// Plateau
|
// Plateau
|
||||||
static Table *table = NULL;
|
static Table *table = NULL;
|
||||||
|
static TTF_Font *font = NULL;
|
||||||
|
|
||||||
// Initialise le programme
|
// Initialise le programme
|
||||||
static void init(void);
|
static void init(void);
|
||||||
|
|
|
@ -5,16 +5,13 @@
|
||||||
|
|
||||||
#include "plateau.h"
|
#include "plateau.h"
|
||||||
|
|
||||||
static TTF_Font *font = NULL;
|
|
||||||
static SDL_Surface *surface = NULL;
|
|
||||||
|
|
||||||
// Charge la police d'écriture
|
// Charge la police d'écriture
|
||||||
void load_font(int quality);
|
TTF_Font *load_font(int quality);
|
||||||
|
|
||||||
// Ecrit du texte à une certaine position
|
// Écrit du texte à une certaine position
|
||||||
void write_text(GLfloat x, GLfloat y, char *text);
|
void write_text(TTF_Font *font, GLfloat x, GLfloat y, char *text);
|
||||||
|
|
||||||
// Décharge la police
|
// Décharge la police
|
||||||
void unload_font(void);
|
void unload_font(TTF_Font *font);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,7 +15,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
void init(void) {
|
void init(void) {
|
||||||
gl4dpInitScreen();
|
gl4dpInitScreen();
|
||||||
load_font(60);
|
font = load_font(60);
|
||||||
|
|
||||||
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));
|
||||||
|
@ -25,7 +25,7 @@ void init(void) {
|
||||||
|
|
||||||
void quit(void) {
|
void quit(void) {
|
||||||
free_table(table);
|
free_table(table);
|
||||||
unload_font();
|
unload_font(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw(void) {
|
void draw(void) {
|
||||||
|
@ -35,6 +35,6 @@ void draw(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void job(void) {
|
void job(void) {
|
||||||
write_text(1.2, 10., "Othello");
|
write_text(font, 1.2, 10., "Othello");
|
||||||
draw_table(table);
|
draw_table(table);
|
||||||
}
|
}
|
||||||
|
|
11
src/text.c
11
src/text.c
|
@ -2,22 +2,23 @@
|
||||||
#include "SDL_ttf.h"
|
#include "SDL_ttf.h"
|
||||||
#include <GL4D/gl4dp.h>
|
#include <GL4D/gl4dp.h>
|
||||||
|
|
||||||
void load_font(int quality) {
|
TTF_Font *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", 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
|
// TODO: Make scale depend of the text length
|
||||||
gl4dpCopyFromSDLSurfaceWithTransforms(surface, (GLfloat[2]){.3, -.1},
|
gl4dpCopyFromSDLSurfaceWithTransforms(surface, (GLfloat[2]){.3, -.1},
|
||||||
(GLfloat[2]){x, y});
|
(GLfloat[2]){x, y});
|
||||||
}
|
}
|
||||||
|
|
||||||
void unload_font(void) { TTF_CloseFont(font); }
|
void unload_font(TTF_Font *font) { TTF_CloseFont(font); }
|
||||||
|
|
Reference in a new issue