2016-10-03 18:12:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "glclasses.hpp"
|
|
|
|
|
|
|
|
#include <glm/vec2.hpp>
|
|
|
|
|
|
|
|
// based on sources of knoc/chaqu
|
|
|
|
|
|
|
|
namespace endofthejedi {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This sprite struct stores all information needed to render an
|
|
|
|
* arbitrary PNG texture to a quad.
|
|
|
|
*
|
|
|
|
* If the loaded texture dimensions have no powers of a bit more space is
|
|
|
|
* allocated and extra padding is added.
|
|
|
|
*/
|
|
|
|
class ImageTexture {
|
|
|
|
public:
|
|
|
|
ImageTexture(const std::string &filename) : m_path(filename), m_valid(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~ImageTexture()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Try to load a PNG image from file into an opengl texture.
|
|
|
|
*
|
|
|
|
* @param path Path of PNG file
|
|
|
|
* @param texture The used texture id will be saved there.
|
|
|
|
* @param width Width of the loaded texture in pixels.
|
|
|
|
* @param height Height of the loaded texture in pixels.
|
|
|
|
* @param uv_scale_x Horizontal portion of the screen which is padded to get
|
|
|
|
* power-of-two texture.
|
|
|
|
* @param uv_scale_y Vertical portion of the screen which is padded to get
|
|
|
|
* power-of-two texture.
|
|
|
|
*
|
|
|
|
* Note: The current active texture unit should be bound (GL_TEXTURE0 etc...)
|
|
|
|
* before calling this
|
|
|
|
*
|
|
|
|
* @return true if loading suceeded, false on errors.
|
|
|
|
*/
|
|
|
|
bool loadPng();
|
|
|
|
|
|
|
|
bool valid() const { return m_valid; }
|
|
|
|
|
2016-10-03 19:14:07 +00:00
|
|
|
glm::vec2 size() const { return m_size; }
|
|
|
|
glm::vec2 uvScale() const { return m_uvScale; }
|
2016-10-03 18:12:09 +00:00
|
|
|
|
|
|
|
GLuint textureId() const { return m_texture_id; }
|
|
|
|
|
|
|
|
public:
|
2016-10-03 19:14:07 +00:00
|
|
|
std::string m_path; // path for the loaded texture is saved here
|
|
|
|
glm::vec2 m_size; // used width/height of the pixels of the texture
|
|
|
|
glm::vec2 m_uvScale; // factor to scale uv-coordinates to get rid of non-power-of-two padding
|
2016-10-03 18:12:09 +00:00
|
|
|
|
2016-10-03 19:14:07 +00:00
|
|
|
bool m_valid;
|
2016-10-03 18:12:09 +00:00
|
|
|
|
|
|
|
GLuint m_texture_id; // texture binding id
|
|
|
|
};
|
|
|
|
}
|