-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.cpp
More file actions
executable file
·44 lines (39 loc) · 1.14 KB
/
texture.cpp
File metadata and controls
executable file
·44 lines (39 loc) · 1.14 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
#include <iostream>
#include "texture.h"
Texture::Texture(GLenum TextureTarget, const std::string& FileName)
{
m_textureTarget = TextureTarget;
m_fileName = FileName;
m_pImage = NULL;
}
Texture::Texture()
{
m_textureTarget = NULL;
m_fileName = "";
m_pImage = NULL;
}
bool Texture::Load()
{
try
{
m_pImage = new Magick::Image(m_fileName);
m_pImage->write(&m_blob, "RGBA");
}
catch (Magick::Error& Error)
{
std::cout << "Error loading texture '" << m_fileName << "': " << Error.what() << std::endl;
return false;
}
//m_pImage->display();
glGenTextures(1, &m_textureObj);
glBindTexture(m_textureTarget, m_textureObj);
glTexImage2D(m_textureTarget, 0, GL_RGB, m_pImage->columns(), m_pImage->rows(), -0.5, GL_RGBA, GL_UNSIGNED_BYTE, m_blob.data());
glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
return true;
}
void Texture::Bind(GLenum TextureUnit)
{
glActiveTexture (TextureUnit);
glBindTexture (m_textureTarget, m_textureObj);
}