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. --- image.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 image.cpp (limited to 'image.cpp') diff --git a/image.cpp b/image.cpp new file mode 100644 index 0000000..db385db --- /dev/null +++ b/image.cpp @@ -0,0 +1,50 @@ +#include "image.h" + +#include "gl.h" + +#include "stb_image.h" + +Image::Image() { + data = 0; +} + +Image::Image(const std::string& filename) { + load(filename); +} + +Image::~Image() { + if(data) { + stbi_image_free(data); + } +} + +void Image::load(const std::string& filename) { + int w, h, ch; + data = stbi_load(filename.c_str(), &w, &h, &ch, 4); + + width = w; + height = h; + + unsigned int format; + if(ch == 4) { + format = GL_RGBA; + } else { + format = GL_RGB; + } +} + +unsigned int Image::w() const { + return width; +} + +unsigned int Image::h() const { + return height; +} + +unsigned int Image::f() const { + return format; +} + +const void* Image::d() const { + return data; +} -- cgit v1.2.3