summaryrefslogtreecommitdiff
path: root/texture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'texture.cpp')
-rw-r--r--texture.cpp26
1 files changed, 9 insertions, 17 deletions
diff --git a/texture.cpp b/texture.cpp
index ba7d9c7..df84961 100644
--- a/texture.cpp
+++ b/texture.cpp
@@ -1,31 +1,23 @@
#include <stdexcept>
#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"));
}