From 812b420c7512ba501877d3b47ebab1dfadff4246 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sun, 28 Feb 2010 00:12:34 +0100 Subject: Check pixel format when loading textures. --- texture.cpp | 6 +++++- texture.h | 1 + texturesdl.cpp | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/texture.cpp b/texture.cpp index cbf9f40..1678a97 100755 --- a/texture.cpp +++ b/texture.cpp @@ -21,5 +21,9 @@ void Texture::build() { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); //glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); - gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_BGRA, GL_UNSIGNED_BYTE, data); + if(byte_per_pixel == 4) { + gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_BGRA, GL_UNSIGNED_BYTE, data); + } else if(byte_per_pixel == 3) { + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_BGR, GL_UNSIGNED_BYTE, data); + } } diff --git a/texture.h b/texture.h index 33f6178..14e500f 100755 --- a/texture.h +++ b/texture.h @@ -8,6 +8,7 @@ class Texture { unsigned char* data; unsigned int width; unsigned int height; + unsigned int byte_per_pixel; unsigned int texture; }; #endif // _TEXTURE_H_ diff --git a/texturesdl.cpp b/texturesdl.cpp index ea7d9ac..716ea03 100755 --- a/texturesdl.cpp +++ b/texturesdl.cpp @@ -8,6 +8,7 @@ TextureSDL::TextureSDL(const char* filename) { width = image->w; height = image->h; + byte_per_pixel = image->format->BytesPerPixel; data = (unsigned char*)image->pixels; build(); -- cgit v1.2.3