Raftel Engine
 
Loading...
Searching...
No Matches
texture.hpp
Go to the documentation of this file.
1
17
18#ifndef __TEXTURE_H__
19#define __TEXTURE_H__ 1
20
21#pragma once
22
23#include <GL/glew.h>
24#include <iostream>
25#include <raftel/global_macros.hpp>
26#include <vector>
27
28namespace Raftel {
29
30 class ShaderProgram;
40 public:
41 unsigned char* data;
42 int width;
43 int height;
45
54 TextureImage(unsigned char* data, int width, int height, int n_channel);
55
60
67 MOVABLE_BUT_NOT_COPYABLE(TextureImage)
68
69 private:
70
71 };
72
80
87
88 class Texture {
89 public:
90 GLuint id;
92
97
114 Texture(const std::vector<std::string>& faces);
115
122
127
137 static std::shared_ptr<Texture> loadTexture(const std::string& texturePath);
138
154 static std::shared_ptr<Texture> loadCubemap(const std::vector<std::string>& faces);
155
166 void bind(int unit) const;
167
173 const std::string& getLastError() const { return lastError; }
174
181 MOVABLE_BUT_NOT_COPYABLE(Texture)
182
183
188 GLuint getID() const { return id; }
189
190 private:
200 static TextureImage LoadTexture(const char* path);
201
212 void setError(const std::string& errorMessage, const char* file, int line);
213 std::string lastError;
214 };
215}
216#endif
A class to represent an OpenGL shader program, combining vertex and fragment shaders.
Definition shader.hpp:119
Represents an OpenGL texture object.
Definition texture.hpp:88
Texture()
Default constructor that initializes the texture ID to 0.
Definition texture.hpp:96
const std::string & getLastError() const
Gets the last error message generated by texture operations.
Definition texture.hpp:173
GLuint getID() const
Move constructor.
Definition texture.hpp:188
Texture(TextureImage image)
Constructor that creates an OpenGL texture from a TextureImage.
~Texture()
Destructor that deletes the OpenGL texture.
TextureType type
Specifies the type of texture (2D or Cubemap)
Definition texture.hpp:91
Texture(const std::vector< std::string > &faces)
Constructs a cubemap texture from six image files.
void bind(int unit) const
Binds the texture to a texture unit.
static std::shared_ptr< Texture > loadCubemap(const std::vector< std::string > &faces)
Loads a cubemap texture from six image files.
GLuint id
OpenGL texture ID.
Definition texture.hpp:90
static std::shared_ptr< Texture > loadTexture(const std::string &texturePath)
Loads a texture from a file and creates an OpenGL texture object.
Represents an image containing texture data.
Definition texture.hpp:39
~TextureImage()
Destructor that frees the image data.
unsigned char * data
Pointer to the raw image data.
Definition texture.hpp:41
int n_channel
Number of channels in the image (e.g., 3 for RGB, 4 for RGBA).
Definition texture.hpp:44
int width
Width of the image.
Definition texture.hpp:42
TextureImage(unsigned char *data, int width, int height, int n_channel)
Construct a TextureImage object.
int height
Height of the image.
Definition texture.hpp:43
TextureType
Specifies the type of texture.
Definition texture.hpp:76