Texture - Horizon-NTH/HorizonGUI GitHub Wiki

Texture

Overview

The Texture class in the hgui::kernel namespace is designed for handling 2D textures. It provides the ability to load, manage, use textures in rendering and let user choose the options through a structure. The class encapsulates a texture ID, along with an associated image, and facilitates texture binding. The class is defined in the header file Texture.h.

TextureOption Structure

The TextureOption structure allow the user to choose it's desired wrapping, filtering options for the texture he is creating. Check this page if you want more information about these options.

  • GLint wrap_s: Texture wrapping on s-axis (default is GL_CLAMP_TO_EDGE).
  • GLint wrap_t: Texture wrapping on t-axis (default is GL_CLAMP_TO_EDGE).
  • GLint min_filter: Texture minifying filter (default is GL_LINEAR).
  • GLint mag_filter: Texture magnifying filter (default is GL_LINEAR).

Texture Class

Constructors

  • explicit Texture(const std::shared_ptr<Image>& image, TextureOption options = {}): Constructs a Texture object using a shared pointer to an image and an optional options. The constructor initializes the texture and sets its parameters.

Member Functions

  • void bind() const: Binds the texture, making it active for rendering.

  • GLuint get_id() const: Retrieves the ID of the texture.

  • const std::shared_ptr<Image>& get_image() const: Retrieves the associated image as a shared pointer.

Example Usage

#include <hgui/header/Texture.h>

// Example Usage of Texture class
std::shared_ptr<Image> textureImage = hgui::image_loader("path_to_texture.png");
hgui::kernel::Texture texture(textureImage);

// Bind the texture for rendering
texture.bind();

// Use the texture for rendering

Note: In the "Example Usage" section, ensure you replace "path_to_texture.png" with the actual path to the texture image you want to use and if you want to read more about the image_loader function, see this.

⚠️ **GitHub.com Fallback** ⚠️