-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtexture.cpp
More file actions
66 lines (58 loc) · 1.71 KB
/
texture.cpp
File metadata and controls
66 lines (58 loc) · 1.71 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
61
62
63
64
65
66
#include "texture.h"
Texture::Texture()
{
_current = 0;
}
void Texture::load(QString url)
{
_url.append(url);
_texName = new GLuint[_url.size()];
glGenTextures(_url.size(), _texName);
for(int i=0; i<_url.size(); i++)
{
QImage* img = loadImage(_url[i]);
if (img != NULL) {
glBindTexture(GL_TEXTURE_2D, _texName[i]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, img->width(),img->height(),0, GL_RGBA,GL_UNSIGNED_BYTE, img->bits());
}
delete img;
}
}
void Texture::next()
{
_current = (_current + 1) % _url.size();
}
void Texture::setCurrent(int index)
{
_current = index;
}
void Texture::setSamplerState()
{
glGenSamplers(3, &_samplerState);
glSamplerParameteri(_samplerState, GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameteri(_samplerState, GL_TEXTURE_WRAP_T, GL_REPEAT);
glSamplerParameteri(_samplerState, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glSamplerParameteri(_samplerState, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glSamplerParameterf(_samplerState, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16.0f);
}
GLuint Texture::getText()
{
return _texName[_current];
}
GLuint Texture::getSamplerState()
{
return _samplerState;
}
QImage* Texture::loadImage(QString & filename)
{
QImage img(filename);
if (img.isNull())
{
cerr << "Unable to load " << filename.toStdString() << endl;
return NULL;
}
cout << "Loading " << filename.toStdString() << ", "<< img.width() << "x" << img.height() << " pixels" << endl;
return new QImage(QGLWidget::convertToGLFormat(img));
}