Represents an OpenGL texture object. More...
#include <texture.hpp>
Public Member Functions | |
Texture () | |
Default constructor that initializes the texture ID to 0. | |
Texture (const std::vector< std::string > &faces) | |
Constructs a cubemap texture from six image files. | |
Texture (TextureImage image) | |
Constructor that creates an OpenGL texture from a TextureImage . | |
~Texture () | |
Destructor that deletes the OpenGL texture. | |
void | bind (int unit) const |
Binds the texture to a texture unit. | |
const std::string & | getLastError () const |
Gets the last error message generated by texture operations. | |
GLuint | getID () const |
Move constructor. | |
Static Public Member Functions | |
static std::shared_ptr< Texture > | loadTexture (const std::string &texturePath) |
Loads a texture from a file and creates an OpenGL texture object. | |
static std::shared_ptr< Texture > | loadCubemap (const std::vector< std::string > &faces) |
Loads a cubemap texture from six image files. | |
Public Attributes | |
GLuint | id |
OpenGL texture ID. | |
TextureType | type |
Specifies the type of texture (2D or Cubemap) | |
Represents an OpenGL texture object.
The Texture
class wraps the OpenGL texture object, providing functions to load, bind, and manage textures. It also includes functionality for error handling related to texture loading.
Definition at line 88 of file texture.hpp.
|
inline |
Default constructor that initializes the texture ID to 0.
Definition at line 96 of file texture.hpp.
Raftel::Texture::Texture | ( | const std::vector< std::string > & | faces | ) |
Constructs a cubemap texture from six image files.
This constructor loads a set of six images and creates a cubemap texture used for skyboxes or environment mapping.
The images must be provided in the following order:
faces | A vector containing the file paths of the six images. |
Raftel::Texture::Texture | ( | TextureImage | image | ) |
Constructor that creates an OpenGL texture from a TextureImage
.
image | The TextureImage that contains the image data to create the texture. |
void Raftel::Texture::bind | ( | int | unit | ) | const |
Binds the texture to a texture unit.
This function binds the texture to the specified texture unit and sets the corresponding shader sampler to the texture unit.
unit | The texture unit to bind the texture to (e.g., 0, 1, etc.). |
sample | The name of the sampler uniform in the shader. |
shader_program | The shader program to which the texture is bound. |
|
inline |
Move constructor.
Transfers ownership of the OpenGL texture ID from another Texture
.
other | The Texture to move from. |
Gets the OpenGL texture ID.
Definition at line 188 of file texture.hpp.
|
inline |
Gets the last error message generated by texture operations.
Definition at line 173 of file texture.hpp.
|
static |
Loads a cubemap texture from six image files.
This function creates an OpenGL cubemap texture using the six provided images representing the faces of a cube. The order of the images must be:
faces | A vector containing the file paths of the six images. |
|
static |
Loads a texture from a file and creates an OpenGL texture object.
This function uses the stb_image
library to load an image from disk and then creates an OpenGL texture object with the image data.
texturePath | The file path to the texture image. |
GLuint Raftel::Texture::id |
OpenGL texture ID.
Definition at line 90 of file texture.hpp.
TextureType Raftel::Texture::type |
Specifies the type of texture (2D or Cubemap)
Definition at line 91 of file texture.hpp.