allow for writeText to use a different texture background that the one we will be write on
This commit is contained in:
parent
0bdb9a18fe
commit
6393d1d7f3
4 changed files with 12 additions and 11 deletions
|
@ -20,7 +20,7 @@ int initFont(TTF_Font **, char *, int);
|
|||
* Renvoie 2 en cas de problème de surface avec la SDL
|
||||
*
|
||||
* Renvoie 0 en cas de succès */
|
||||
int writeText(GLuint *, TTF_Font *, const char *, SDL_Color, GLboolean);
|
||||
int writeText(GLuint *, TTF_Font *, const char *, SDL_Color, GLuint *);
|
||||
|
||||
// Libère une police de la mémoire
|
||||
void freeFont(TTF_Font *);
|
||||
|
|
|
@ -54,7 +54,7 @@ static void init(void) {
|
|||
"- Audio : beepbox\n"
|
||||
"- Talent : aucun\n"
|
||||
"- Librairies : GL4D, SDL2 et extensions",
|
||||
(SDL_Color){255, 255, 255, 255}, GL_FALSE)) {
|
||||
(SDL_Color){255, 255, 255, 255}, NULL)) {
|
||||
exit(errStatus);
|
||||
}
|
||||
|
||||
|
|
13
src/font.c
13
src/font.c
|
@ -15,7 +15,7 @@ int initFont(TTF_Font **font, char *filename, int size) {
|
|||
}
|
||||
|
||||
int writeText(GLuint *_textTexId, TTF_Font *font, const char *text,
|
||||
SDL_Color color, GLboolean keep_previous) {
|
||||
SDL_Color color, GLuint *backgroundTextureId) {
|
||||
SDL_Surface *d, *s;
|
||||
// Create text
|
||||
if (!(d = TTF_RenderUTF8_Blended_Wrapped(font, text, color, 0))) {
|
||||
|
@ -32,10 +32,10 @@ int writeText(GLuint *_textTexId, TTF_Font *font, const char *text,
|
|||
return 2;
|
||||
}
|
||||
|
||||
if (keep_previous) {
|
||||
if (backgroundTextureId) {
|
||||
// On garde la texture déjà présente
|
||||
assert(_textTexId);
|
||||
glBindTexture(GL_TEXTURE_2D, *_textTexId);
|
||||
assert(*backgroundTextureId);
|
||||
glBindTexture(GL_TEXTURE_2D, *backgroundTextureId);
|
||||
|
||||
GLint w, h;
|
||||
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
|
||||
|
@ -57,15 +57,16 @@ int writeText(GLuint *_textTexId, TTF_Font *font, const char *text,
|
|||
SDL_BlitScaled(old, NULL, s, NULL);
|
||||
|
||||
SDL_FreeSurface(old);
|
||||
|
||||
} else {
|
||||
// Aucune texture existante, donc on la créée
|
||||
glGenTextures(1, _textTexId);
|
||||
assert(_textTexId);
|
||||
glBindTexture(GL_TEXTURE_2D, *_textTexId);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, *_textTexId);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
}
|
||||
|
||||
// Copie le texte sur la surface finale
|
||||
SDL_BlitSurface(d, NULL, s, NULL);
|
||||
|
|
|
@ -44,7 +44,7 @@ static void init(void) {
|
|||
exit(3);
|
||||
}
|
||||
if (writeText(&_texId[1], font, "macron = loser", (SDL_Color){0, 0, 0, 255},
|
||||
GL_TRUE)) {
|
||||
&_texId[0])) {
|
||||
exit(3);
|
||||
}
|
||||
freeFont(font);
|
||||
|
|
Reference in a new issue