-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.cpp
More file actions
52 lines (44 loc) · 1.31 KB
/
texture.cpp
File metadata and controls
52 lines (44 loc) · 1.31 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
#include "texture.h"
texture::texture()
{
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 512, 512,
0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
textureSize = glm::ivec2(512, 512);
}
texture::texture(glm::ivec2 _size)
{
glGenTextures(1, &id);
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _size.x, _size.y,
0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
textureSize = _size;
}
texture::texture(std::string _path)
{
unsigned char* data = stbi_load(_path.c_str(), &textureSize.x, &textureSize.y, NULL, 4);
if (!data) { throw std::exception(); }
glGenTextures(1, &id);
if (!id) { throw std::exception(); }
glBindTexture(GL_TEXTURE_2D, id);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureSize.x, textureSize.y, 0, GL_RGBA,
GL_UNSIGNED_BYTE, data);
free(data);
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE, 0);
}
glm::ivec2 texture::getSize()
{
return textureSize;
}
GLuint texture::getId()
{
return id;
}