summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Bergli Heier <snakebite@jvnv.net>2010-02-28 00:12:34 +0100
committerJon Bergli Heier <snakebite@jvnv.net>2010-02-28 00:12:34 +0100
commit812b420c7512ba501877d3b47ebab1dfadff4246 (patch)
treefd9b0880ff55865b7759c65c105547a56de8af38
parent42fcaf7d7d374bdae934b5d9aeb32af964872681 (diff)
Check pixel format when loading textures.
-rwxr-xr-xtexture.cpp6
-rwxr-xr-xtexture.h1
-rwxr-xr-xtexturesdl.cpp1
3 files changed, 7 insertions, 1 deletions
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();