-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterial.cpp
More file actions
91 lines (77 loc) · 2.11 KB
/
Material.cpp
File metadata and controls
91 lines (77 loc) · 2.11 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "Material.h"
#include <QDebug>
Material::Material(Node *parent) : Node(parent)
{
setName("material");
setType("Material");
_texId = 0;
_hasTexture = false;
createDOF(DOF::ColorR, true, true, true, 200, 0, 255);
createDOF(DOF::ColorG, true, true, true, 200, 0, 255);
createDOF(DOF::ColorB, true, true, true, 200, 0, 255);
createDOF(DOF::ColorA, true, true, true, 255, 0, 255);
createDOF(DOF::Diffuse, true, true, true, 0, 1, 1);
createDOF(DOF::Specular, true, true, true, 0, 1, 1);
}
Material::~Material()
{
}
void Material::setColor(const QColor &color)
{
setDOFValue(DOF::ColorR, color.red());
setDOFValue(DOF::ColorG, color.green());
setDOFValue(DOF::ColorB, color.blue());
setDOFValue(DOF::ColorA, color.alpha());
}
QColor Material::color() const
{
return QColor(DOFValue(DOF::ColorR),
DOFValue(DOF::ColorG),
DOFValue(DOF::ColorB),
DOFValue(DOF::ColorA));
}
bool Material::hasTexture() const
{
return _hasTexture;
}
void Material::setHasTexture(bool hasTexture)
{
if (_texId > 0)
_hasTexture = hasTexture;
else
_hasTexture = false;
}
GLuint Material::texture() const
{
return _texId;
}
bool Material::loadTexture(const QString &filename)
{
QImage img(filename);
if (img.isNull())
return false;
img = QGLWidget::convertToGLFormat(img);
glGenTextures(1, &_texId);
glBindTexture(GL_TEXTURE_2D, _texId);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img.width(), img.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, img.bits());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
setHasTexture(true);
return hasTexture();
}
float Material::diffuseCoef() const
{
return DOFValue(DOF::Diffuse);
}
void Material::setDiffuseCoef(float diffuseCoef)
{
setDOFValue(DOF::Diffuse, diffuseCoef);
}
float Material::specularCoef() const
{
return DOFValue(DOF::Specular);
}
void Material::setSpecularCoef(float specularCoef)
{
setDOFValue(DOF::Specular, specularCoef);
}