summaryrefslogtreecommitdiff
path: root/texture.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-17 18:54:26 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-01-17 18:54:26 +0000
commit43a87590f45aa6e55724d30d0c2d0d34b407a57e (patch)
tree21ce8e8886f8aa58b159419b7d885f57d9a37580 /texture.cpp
parentInitial commit (diff)
downloadilt-43a87590f45aa6e55724d30d0c2d0d34b407a57e.tar.bz2
ilt-43a87590f45aa6e55724d30d0c2d0d34b407a57e.tar.xz
ilt-43a87590f45aa6e55724d30d0c2d0d34b407a57e.zip
First cut modernizing and sanitizing
Diffstat (limited to 'texture.cpp')
-rw-r--r--texture.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/texture.cpp b/texture.cpp
index aae16b3..a388b32 100644
--- a/texture.cpp
+++ b/texture.cpp
@@ -1,14 +1,15 @@
#include "texture.h"
#include "stb_image.h"
-#include <iostream>
+#include <stdexcept>
-Texture::Texture(const std::string & fileName)
+Texture::Texture(const std::string & fileName) : m_texture {}
{
int width, height, numComponents;
unsigned char * data = stbi_load((fileName).c_str(), &width, &height, &numComponents, 4);
- if (data == NULL)
- std::cerr << "Unable to load texture: " << fileName << std::endl;
+ if (!data) {
+ throw std::runtime_error {"Unable to load texture: " + fileName};
+ }
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
@@ -28,7 +29,7 @@ Texture::~Texture()
}
void
-Texture::Bind()
+Texture::Bind() const
{
glBindTexture(GL_TEXTURE_2D, m_texture);
}