From f84b25fc8e0619ad24974c4dc520449827f8d193 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Fri, 28 Jan 2011 22:08:37 +0100 Subject: Split out image loading from Texture into Image. --- texture.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'texture.cpp') diff --git a/texture.cpp b/texture.cpp index ba7d9c7..df84961 100644 --- a/texture.cpp +++ b/texture.cpp @@ -1,31 +1,23 @@ #include #include "texture.h" -#include "stb_image.h" #include "gl.h" Texture::Texture() { glGenTextures(1, &texture); } +Texture::Texture(const Image& image) { + glGenTextures(1, &texture); + load(image); +} + Texture::Texture(const std::string& filename) { glGenTextures(1, &texture); - load(filename); + load(Image(filename)); } -void Texture::load(const std::string& filename) { - int w, h, ch; - uint8_t* data = stbi_load(filename.c_str(), &w, &h, &ch, 4); - - unsigned int format; - if(ch == 4) { - format = GL_RGBA; - } else { - format = GL_RGB; - } - - build(data, format, w, h); - - stbi_image_free(data); +void Texture::load(const Image& image) { + build(image.d(), image.f(), image.w(), image.h()); } void Texture::bind() const { @@ -44,7 +36,7 @@ unsigned int Texture::h() const { return height; } -void Texture::build(void* data, unsigned int format, unsigned int w, unsigned int h) { +void Texture::build(const void* data, unsigned int format, unsigned int w, unsigned int h) { if(!data) { throw(std::runtime_error("No texture data")); } -- cgit v1.2.3