summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-06-30 23:31:01 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-06-30 23:31:01 +0200
commitab8c1e0eeffedb0e5979874fba64b305effdb2d3 (patch)
tree8b6f3b996a0333587c5546527ab148d4740ab79d
parentd74b4f20e722ecd732e70e76985c7c936d0f82a2 (diff)
Changed Texture-API.
-rw-r--r--texture.cpp20
-rw-r--r--texture.h13
-rw-r--r--texturesdl.cpp8
3 files changed, 29 insertions, 12 deletions
diff --git a/texture.cpp b/texture.cpp
index c3575f2..c8c5541 100644
--- a/texture.cpp
+++ b/texture.cpp
@@ -3,14 +3,30 @@
#include "texture.h"
#include <stdio.h>
-unsigned int Texture::tex() {
+void Texture::bind() const {
+ glBindTexture(GL_TEXTURE_2D, texture);
+}
+
+unsigned int Texture::tex() const {
return texture;
}
-void Texture::build() {
+unsigned int Texture::w() const {
+ return width;
+}
+
+unsigned int Texture::h() const {
+ return height;
+}
+
+void Texture::build(void* data, unsigned int format, unsigned int w, unsigned int h) {
if(!data) {
throw(std::runtime_error("No texture data"));
}
+
+ width = w;
+ height = h;
+
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
diff --git a/texture.h b/texture.h
index c88104f..ca7fef1 100644
--- a/texture.h
+++ b/texture.h
@@ -1,14 +1,19 @@
#ifndef _TEXTURE_H_
#define _TEXTURE_H_
+
+#include <stdint.h>
+
class Texture {
public:
- unsigned int tex();
+ void bind() const;
+ unsigned int tex() const;
+ unsigned int w() const;
+ unsigned int h() const;
protected:
- void build();
- unsigned char* data;
+ void build(void* data, unsigned int format, unsigned int w, unsigned int h);
unsigned int width;
unsigned int height;
- unsigned int format;
unsigned int texture;
};
+
#endif // _TEXTURE_H_
diff --git a/texturesdl.cpp b/texturesdl.cpp
index bab760b..94e1e2d 100644
--- a/texturesdl.cpp
+++ b/texturesdl.cpp
@@ -6,18 +6,14 @@
TextureSDL::TextureSDL(const char* filename) {
SDL_Surface* image = IMG_Load(filename);
- width = image->w;
- height = image->h;
-
+ unsigned int format;
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();
+ build(image->pixels, format, image->w, image->h);
SDL_FreeSurface(image);
}