From 43a87590f45aa6e55724d30d0c2d0d34b407a57e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 17 Jan 2021 18:54:26 +0000 Subject: First cut modernizing and sanitizing --- texture.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'texture.cpp') 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 +#include -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); } -- cgit v1.2.3