summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-05-21 22:15:35 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-05-21 22:15:35 +0200
commit98f0d881978eb1c35c9bc4ab7d951e22f873102b (patch)
tree9b966785139dcf1a9e85cb8acf7c358652753d03 /engine
parent267bebfc227c94f543a39e2aa75fb101bc06932e (diff)
Fixed RGB vs BGR in texture loading.
Diffstat (limited to 'engine')
-rw-r--r--engine/texture.cpp14
-rw-r--r--engine/texture.h2
-rw-r--r--engine/texturesdl.cpp10
3 files changed, 11 insertions, 15 deletions
diff --git a/engine/texture.cpp b/engine/texture.cpp
index ca9d8e7..c3575f2 100644
--- a/engine/texture.cpp
+++ b/engine/texture.cpp
@@ -1,10 +1,4 @@
-#ifndef __APPLE__
-#include <GL/gl.h>
-#include <GL/glut.h>
-#else
-#include <OpenGL/gl.h>
-#include <GLUT/glut.h>
-#endif
+#include <SDL/SDL_opengl.h>
#include <stdexcept>
#include "texture.h"
#include <stdio.h>
@@ -21,9 +15,5 @@ void Texture::build() {
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- if(byte_per_pixel == 4) {
- gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
- } else if(byte_per_pixel == 3) {
- gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
- }
+ gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, format, GL_UNSIGNED_BYTE, data);
}
diff --git a/engine/texture.h b/engine/texture.h
index 14e500f..c88104f 100644
--- a/engine/texture.h
+++ b/engine/texture.h
@@ -8,7 +8,7 @@ class Texture {
unsigned char* data;
unsigned int width;
unsigned int height;
- unsigned int byte_per_pixel;
+ unsigned int format;
unsigned int texture;
};
#endif // _TEXTURE_H_
diff --git a/engine/texturesdl.cpp b/engine/texturesdl.cpp
index 8e112ef..bab760b 100644
--- a/engine/texturesdl.cpp
+++ b/engine/texturesdl.cpp
@@ -1,6 +1,6 @@
-#include <iostream>
#include <stdexcept>
#include <SDL/SDL_image.h>
+#include <SDL/SDL_opengl.h>
#include "texturesdl.h"
TextureSDL::TextureSDL(const char* filename) {
@@ -8,7 +8,13 @@ TextureSDL::TextureSDL(const char* filename) {
width = image->w;
height = image->h;
- byte_per_pixel = image->format->BytesPerPixel;
+
+ if(image->format->BytesPerPixel == 4) {
+ format = image->format->Bshift ? GL_RGBA : GL_BGRA;
+ } else {
+ format = image->format->Bshift ? GL_RGB : GL_BGR;
+ }
+
data = (unsigned char*)image->pixels;
build();