diff options
author | Jon Bergli Heier <snakebite@jvnv.net> | 2010-02-28 00:12:34 +0100 |
---|---|---|
committer | Jon Bergli Heier <snakebite@jvnv.net> | 2010-02-28 00:12:34 +0100 |
commit | 812b420c7512ba501877d3b47ebab1dfadff4246 (patch) | |
tree | fd9b0880ff55865b7759c65c105547a56de8af38 | |
parent | 42fcaf7d7d374bdae934b5d9aeb32af964872681 (diff) |
Check pixel format when loading textures.
-rwxr-xr-x | texture.cpp | 6 | ||||
-rwxr-xr-x | texture.h | 1 | ||||
-rwxr-xr-x | texturesdl.cpp | 1 |
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); + } } @@ -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(); |