-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTexture.cpp
More file actions
39 lines (32 loc) · 1.34 KB
/
Texture.cpp
File metadata and controls
39 lines (32 loc) · 1.34 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
#include "main.h"
Texture::Texture(const std::string& path,glm::vec3 dimension)
: m_RendererID(0), m_FilePath(path), m_LocalBuffer(nullptr)
{
// inintialize 3D texture from file
m_LocalBuffer = load_3d_raw_data(path.c_str(), dimension);
glGenTextures(1, &m_RendererID);
glBindTexture(GL_TEXTURE_3D, m_RendererID); // Bind without slot selection
// glBindTexture(GL_TEXTURE_3D, g_volTexObj);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
// pixel transfer happens here from client to OpenGL server
// glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RED, dimension.x, dimension.y, dimension.z, 0, GL_RED, GL_UNSIGNED_BYTE,m_LocalBuffer);
Unbind();
delete []m_LocalBuffer;
// if (m_LocalBuffer)
// stbi_image_free(m_LocalBuffer);
};
Texture::~Texture(){
glDeleteTextures(1, &m_RendererID);
}
void Texture::Bind(unsigned int slot) const{
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(GL_TEXTURE_2D, m_RendererID);
}
void Texture::Unbind() const{
glBindTexture(GL_TEXTURE_2D, 0);
}