Struct Texture

Struct Documentation

struct Texture

Represents an OpenGL texture loaded from an SDL_Surface.

The Texture class encapsulates the loading, management, and cleanup of an OpenGL texture created from an image file using SDL2. It manages the underlying SDL_Surface and OpenGL texture object, providing access to texture properties and pixel data.

Note

Copying is disabled to prevent multiple ownership of the same texture resource.

Public Functions

Texture() = default

Constructs a Texture object by loading an image from the specified path.

This constructor loads an image using the provided SDL2 wrapper and initializes the OpenGL texture format based on the image’s pixel format. If the image fails to load, or if the image format is unsupported, it throws a std::runtime_error.

Parameters:
  • sdl – Reference to an SDL2 wrapper object used for image loading and error handling.

  • path – Path to the image file to be loaded as a texture.

Throws:

std::runtime_error – If the image cannot be loaded or if the image format is unknown.

Texture(const Texture&) = delete
Texture &operator=(const Texture&) = delete
~Texture()
bool Init(SDL2 &sdl, const std::string &path)
inline GLuint GetGL() const
inline GLsizei GetWidth() const
inline GLsizei GetHeight() const
inline const void *GetPixels() const
inline GLenum GetFormat() const