in case of bad img load, we use red texture as it works with the same value in big and little endian

This commit is contained in:
Mylloon 2023-05-21 10:09:14 +02:00
parent 5a81421c4b
commit fdd97480ad
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -31,18 +31,22 @@ void load_img(const char *filename, GLuint texture) {
glBindTexture(GL_TEXTURE_2D, texture); glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 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_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
SDL_Surface *s = NULL; SDL_Surface *s = NULL;
if (!(s = IMG_Load(filename))) { 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); glBindTexture(GL_TEXTURE_2D, 0);
} }