diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-28 22:08:37 +0100 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2011-01-28 22:08:37 +0100 |
commit | f84b25fc8e0619ad24974c4dc520449827f8d193 (patch) | |
tree | 71c623805bbb10b8e06a44ee40176e304a42f62f /image.cpp | |
parent | 7ebb0e91f63203753420b5a4b75d09d170f204f4 (diff) |
Split out image loading from Texture into Image.
Diffstat (limited to 'image.cpp')
-rw-r--r-- | image.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
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; +} |