summaryrefslogtreecommitdiff
path: root/image.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'image.cpp')
-rw-r--r--image.cpp50
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;
+}