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:
parent
5a81421c4b
commit
fdd97480ad
1 changed files with 10 additions and 6 deletions
12
src/utils.c
12
src/utils.c
|
@ -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,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, s->w, s->h, 0, GL_RGBA,
|
||||||
GL_UNSIGNED_BYTE, s->pixels);
|
GL_UNSIGNED_BYTE, s->pixels);
|
||||||
SDL_FreeSurface(s);
|
SDL_FreeSurface(s);
|
||||||
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue