-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.h
More file actions
60 lines (48 loc) · 1.2 KB
/
Copy pathTexture.h
File metadata and controls
60 lines (48 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
class Texture
{
private:
GLuint id;
int width;
int height;
unsigned int type;
inline GLuint getID() const { return this->id; }
public:
Texture(const char* fileName, GLenum type)
{
this->type = type;
unsigned char* image = SOIL_load_image(fileName, &this->width, &this->height, NULL, SOIL_LOAD_RGBA);
glGenTextures(1, &this->id);
glBindTexture(type, this->id);
glTexParameteri(type, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(type, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(type, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
if (image)
{
glTexImage2D(type, 0, GL_RGBA, this->width, this->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(type);
}
else
{
std::cout << "ERROR::TEXTURE::TEXTURE_LOADING_FAILED: " << fileName << "\n";
}
glActiveTexture(0);
glBindTexture(type, 0);
SOIL_free_image_data(image);
}
~Texture()
{
glDeleteTextures(1, &this->id);
}
void bind(const GLint texture_unit)
{
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(this->type, this->id);
}
void unbind()
{
glActiveTexture(0);
glBindTexture(this->type, 0);
}
};