This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmesh.cpp
58 lines (48 loc) · 1.97 KB
/
mesh.cpp
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
#include "mesh.h"
Mesh::Mesh ()
: material (nullptr)
{
}
void Mesh::draw (QMatrix4x4 projection)
{
// Draw Material
if (material)
{
material -> draw (& program);
// Draw Transform
{
QMatrix4x4 transform;
transform.translate (getGlobalX (), getGlobalY (), getGlobalZ ());
transform.rotate (getGlobalRotationX (), 1.0, 0.0);
transform.rotate (getGlobalRotationY (), 0.0, 1.0);
transform.rotate (getGlobalRotationZ (), 0.0, 0.0, 1.0);
transform.scale (getGlobalScaleX (), getGlobalScaleY (), getGlobalScaleZ ());
program.setUniformValue("mvp_matrix", projection * transform);
}
// Draw Geometry
{
// Tell OpenGL which VBOs to use
// geometry.vertices.bind ();
// geometry.indices.bind ();
// Offset for position
int offset = 0;
// Tell OpenGL programmable pipeline how to locate vertex position data
int vertexLocation = program.attributeLocation ("a_position");
program.enableAttributeArray (vertexLocation);
program.setAttributeBuffer (vertexLocation, GL_FLOAT, offset, 3, sizeof (VertexData));
// Offset for texture coordinate
offset += sizeof (QVector3D);
// Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
int texcoordLocation = program.attributeLocation ("a_texcoord");
program.enableAttributeArray (texcoordLocation);
program.setAttributeBuffer (texcoordLocation, GL_FLOAT, offset, 2, sizeof (VertexData));
// Draw mesh geometry using indices from VBO 1
glDrawElements (GL_TRIANGLE_STRIP, geometry.indices.size () / sizeof (Geometry::indicetype_t), Geometry::gl_enum_type, nullptr);
}
}
}
void Mesh::setMaterial (Material * material)
{
this -> material = material;
material -> initShaders (& program);
}