From ab8c1e0eeffedb0e5979874fba64b305effdb2d3 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Wed, 30 Jun 2010 23:31:01 +0200 Subject: Changed Texture-API. --- texture.cpp | 20 ++++++++++++++++++-- texture.h | 13 +++++++++---- texturesdl.cpp | 8 ++------ 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 -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 + 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); } -- cgit v1.2.3