add the tag

This commit is contained in:
Mylloon 2023-05-21 13:20:50 +02:00
parent 659b08a12d
commit 8bf972d316
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 40 additions and 15 deletions

View file

@ -20,7 +20,7 @@ int initFont(TTF_Font **, char *, int);
* Renvoie 2 en cas de problème de surface avec la SDL * Renvoie 2 en cas de problème de surface avec la SDL
* *
* Renvoie 0 en cas de succès */ * Renvoie 0 en cas de succès */
int writeText(GLuint *, TTF_Font *, const char *, SDL_Color); int writeText(GLuint *, TTF_Font *, const char *, SDL_Color, GLboolean);
// Libère une police de la mémoire // Libère une police de la mémoire
void freeFont(TTF_Font *); void freeFont(TTF_Font *);

View file

@ -54,7 +54,7 @@ static void init(void) {
"- Audio : beepbox\n" "- Audio : beepbox\n"
"- Talent : aucun\n" "- Talent : aucun\n"
"- Librairies : GL4D, SDL2 et extensions", "- Librairies : GL4D, SDL2 et extensions",
(SDL_Color){255, 255, 255, 255})) { (SDL_Color){255, 255, 255, 255}, GL_FALSE)) {
exit(errStatus); exit(errStatus);
} }

View file

@ -15,14 +15,7 @@ int initFont(TTF_Font **font, char *filename, int size) {
} }
int writeText(GLuint *_textTexId, TTF_Font *font, const char *text, int writeText(GLuint *_textTexId, TTF_Font *font, const char *text,
SDL_Color color) { SDL_Color color, GLboolean keep_previous) {
glGenTextures(1, _textTexId);
assert(_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);
SDL_Surface *d, *s; SDL_Surface *d, *s;
if (!(d = TTF_RenderUTF8_Blended_Wrapped(font, text, color, 0))) { if (!(d = TTF_RenderUTF8_Blended_Wrapped(font, text, color, 0))) {
freeFont(font); freeFont(font);
@ -30,16 +23,36 @@ int writeText(GLuint *_textTexId, TTF_Font *font, const char *text,
return 1; return 1;
} }
if (!(s = SDL_CreateRGBSurface(0, d->w, d->h, 32, R_MASK, G_MASK, B_MASK, GLint w, h;
if (keep_previous) {
glBindTexture(GL_TEXTURE_2D, *_textTexId);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
} else {
// Aucune texture existante déjà créer
glGenTextures(1, _textTexId);
assert(_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);
w = d->w, h = d->h;
}
if (!(s = SDL_CreateRGBSurface(0, w, h, 32, R_MASK, G_MASK, B_MASK,
A_MASK))) { A_MASK))) {
freeFont(font); freeFont(font);
fprintf(stderr, "Erreur SDL : %s\n", SDL_GetError()); fprintf(stderr, "Erreur SDL : %s\n", SDL_GetError());
return 2; return 2;
} }
if (keep_previous) {
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, s->pixels);
}
SDL_BlitSurface(d, NULL, s, NULL); SDL_BlitSurface(d, NULL, s, NULL);
SDL_FreeSurface(d); SDL_FreeSurface(d);
glBindTexture(GL_TEXTURE_2D, *_textTexId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->w, s->h, 0, GL_RGBA, glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->w, s->h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, s->pixels); GL_UNSIGNED_BYTE, s->pixels);

View file

@ -38,6 +38,16 @@ static void init(void) {
glGenTextures(1, &_texId); glGenTextures(1, &_texId);
load_img("images/wall.png", _texId); load_img("images/wall.png", _texId);
TTF_Font *font = NULL;
if (initFont(&font, "fonts/Instrument.ttf", 100)) {
exit(3);
}
if (writeText(&_texId, font, "macron = loser",
(SDL_Color){255, 255, 255, 255}, GL_FALSE)) {
exit(3);
}
freeFont(font);
gl4duGenMatrix(GL_FLOAT, matrix_proj); gl4duGenMatrix(GL_FLOAT, matrix_proj);
gl4duGenMatrix(GL_FLOAT, matrix_model); gl4duGenMatrix(GL_FLOAT, matrix_model);
gl4duGenMatrix(GL_FLOAT, matrix_view); gl4duGenMatrix(GL_FLOAT, matrix_view);
@ -51,6 +61,7 @@ static void draw(void) {
GLfloat lum_pos[] = {-2.0f * GLfloat lum_pos[] = {-2.0f *
(float)cos(angle * (GLfloat)M_PI / (5.0f * 180.0f)), (float)cos(angle * (GLfloat)M_PI / (5.0f * 180.0f)),
0.2f, 0.0f, 1.0f}; 0.2f, 0.0f, 1.0f};
const GLfloat distance = 2; // distance from the scene
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glClearColor(0.2f, 0.2f, 0.2f, 1); glClearColor(0.2f, 0.2f, 0.2f, 1);
@ -62,13 +73,14 @@ static void draw(void) {
gl4duFrustumf(-1, 1, -ratio, ratio, 2, 1000); gl4duFrustumf(-1, 1, -ratio, ratio, 2, 1000);
bindAndLoadf(matrix_view); bindAndLoadf(matrix_view);
const GLfloat distance = 2; // distance from the scene
gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0); gl4duLookAtf(0, distance, distance, 0, 0, 0, 0, 1, 0);
// gl4duRotatef(-90, 0, 1, 0); // rotation camera // gl4duRotatef(-90, 0, 1, 0); // rotation camera
bindAndLoadf(matrix_model); bindAndLoadf(matrix_model);
gl4duRotatef(40, 1, 0, 0); gl4duRotatef(45, 1, 0, 0);
gl4duRotatef(40, 0, 0, 1); gl4duRotatef(180, 0, 1, 0);
gl4duRotatef(20, 0, 0, 1);
gl4duScalef(-1, 1, 1);
angle += dt * 90.0f; angle += dt * 90.0f;
gl4duSendMatrices(); gl4duSendMatrices();