summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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();