#ifndef CLIENT_RENDER_TEXTURE_HH_ #define CLIENT_RENDER_TEXTURE_HH_ #include #include #include "client/render/lib/stb_image/stb_image.hh" namespace client { namespace render { // Automatic freeing of a texture from stb image. struct texture { unsigned char* image; int width; int height; int channels; texture(const std::string& dir, const bool flip = false) { stbi_set_flip_vertically_on_load(flip); this->image = stbi_load(dir.c_str(), &this->width, &this->height, &this->channels, 0); if (this->image == nullptr) { throw std::runtime_error("stbi failed to load texture \"" + dir + '\"'); } } texture(const texture&) = delete; texture(texture&&) = delete; ~texture() noexcept { stbi_image_free(image); } }; } // namespace render } // namespace client #endif