From fdd97480ad62d0b2e6e2605cd43a3acd14a4e41a Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sun, 21 May 2023 10:09:14 +0200 Subject: [PATCH] in case of bad img load, we use red texture as it works with the same value in big and little endian --- src/utils.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/utils.c b/src/utils.c index 3be289b..2f117d8 100644 --- a/src/utils.c +++ b/src/utils.c @@ -31,18 +31,22 @@ void load_img(const char *filename, GLuint texture) { glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); SDL_Surface *s = NULL; if (!(s = IMG_Load(filename))) { - fprintf(stderr, "Erreur de chargement de l'image (IMG_Load)\n"); + fprintf(stderr, "Erreur de chargement de l'image (IMG_Load)\n" + "Using red color instead\n"); + GLuint p = 0xFF0000FF; + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, + &p); + } else { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->w, s->h, 0, GL_RGBA, + GL_UNSIGNED_BYTE, s->pixels); + SDL_FreeSurface(s); } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->w, s->h, 0, GL_RGBA, - GL_UNSIGNED_BYTE, s->pixels); - SDL_FreeSurface(s); - glBindTexture(GL_TEXTURE_2D, 0); }