35 texture.m_texture = 0;
49 texture.m_texture = 0;
57 SDL_Surface *surface = IMG_Load(
m_filename.c_str());
59 throw EXCEPTION(
"Failed to load texture:", filename);
64 SDL_FreeSurface(surface);
80 if (surface->format->BytesPerPixel == 4) {
81 format = (surface->format->Rmask == 0x000000ff) ? GL_RGBA : GL_BGRA;
83 format = (surface->format->Rmask == 0x000000ff) ? GL_RGB : GL_BGR;
86 glCheck(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
m_width,
m_height, 0, format, GL_UNSIGNED_BYTE, surface->pixels));
88 glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
89 glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST));
98 glCheck(glBindTexture(GL_TEXTURE_2D, 0));
void loadFromFile(const std::string &filename)
Load the texture from a file on the disk.
static void bind(const Texture *texture)
Bind a texture for rendering.
void loadFromSurface(SDL_Surface *surface)
Load the texture from a SDL_Surface.
GLuint m_texture
Internal OpenGL texture ID.
#define EXCEPTION(args...)
u16 m_width
Width of the texture.
Texture & operator=(Texture &&texture)
Move assignement operator.
Image living on the graphics card that can be used for drawing.
const std::string & filename() const
Return the filename of the texture.
~Texture() noexcept
Destructor.
std::string m_filename
Texture filename.
u16 m_height
Height of the texture.
Texture()=default
Default constructor.