-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexture.cpp
49 lines (38 loc) · 1.16 KB
/
Texture.cpp
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
#include "Texture.h"
Texture::Texture(const char* image, GLenum texType, GLenum slot, GLenum format, GLenum pixelType)
{
type = texType;
int widthImg, heightImg, numColCh;
stbi_set_flip_vertically_on_load(true);
unsigned char* bytes = stbi_load(image, &widthImg, &heightImg, &numColCh, 0);
GLuint texture;
glGenTextures(1, &ID);
glActiveTexture(slot);
glBindTexture(texType, ID);
glTexParameteri(texType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(texType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(texType, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(texType, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(texType, 0, GL_RGBA, widthImg, heightImg, 0, format, pixelType, bytes);
glGenerateMipmap(texType);
stbi_image_free(bytes);
glBindTexture(texType, 0);
}
void Texture::texUnit(Shader shader, const char* uniform, GLuint unit)
{
GLuint texUni = glGetUniformLocation(shader.ID, uniform);
shader.Activate();
glUniform1i(texUni, unit);
}
void Texture::Bind()
{
glBindTexture(type, ID);
}
void Texture::Unbind()
{
glBindTexture(type, 0);
}
void Texture::Delete()
{
glDeleteTextures(1, &ID);
}