diff options
-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(); |