-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathVisualization.h
More file actions
118 lines (103 loc) · 3.75 KB
/
Visualization.h
File metadata and controls
118 lines (103 loc) · 3.75 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#ifndef __VISUALIZATION_H__
#define __VISUALIZATION_H__
#include "Common/Common.h"
#include "MiniGL.h"
namespace PBD
{
class Visualization
{
public:
template<class PositionData>
static void drawMesh(const PositionData &pd, const Utilities::IndexedFaceMesh &mesh, const unsigned int offset, const float * const color);
template<class PositionData>
static void drawTexturedMesh(const PositionData &pd, const Utilities::IndexedFaceMesh &mesh, const unsigned int offset, const float * const color);
};
template<class PositionData>
void Visualization::drawMesh(const PositionData &pd, const Utilities::IndexedFaceMesh &mesh, const unsigned int offset, const float * const color)
{
// draw mesh
const unsigned int *faces = mesh.getFaces().data();
const unsigned int nFaces = mesh.numFaces();
const Vector3r *vertexNormals = mesh.getVertexNormals().data();
if (MiniGL::checkOpenGLVersion(3, 3))
{
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_REAL, GL_FALSE, 0, &pd.getPosition(offset)[0]);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_REAL, GL_FALSE, 0, &vertexNormals[0][0]);
}
else
{
float speccolor[4] = { 1.0, 1.0, 1.0, 1.0 };
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, speccolor);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0f);
glColor3fv(color);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_REAL, 0, &pd.getPosition(0)[0]);
glNormalPointer(GL_REAL, 0, &vertexNormals[0][0]);
}
glDrawElements(GL_TRIANGLES, (GLsizei)3 * mesh.numFaces(), GL_UNSIGNED_INT, mesh.getFaces().data());
if (MiniGL::checkOpenGLVersion(3, 3))
{
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(2);
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
}
}
template<class PositionData>
void Visualization::drawTexturedMesh(const PositionData &pd, const Utilities::IndexedFaceMesh &mesh, const unsigned int offset, const float * const color)
{
// draw mesh
const unsigned int *faces = mesh.getFaces().data();
const unsigned int nFaces = mesh.numFaces();
const Vector3r *vertexNormals = mesh.getVertexNormals().data();
const Vector2r *uvs = mesh.getUVs().data();
MiniGL::bindTexture();
if (MiniGL::checkOpenGLVersion(3,3))
{
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_REAL, GL_FALSE, 0, &pd.getPosition(offset)[0]);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_REAL, GL_FALSE, 0, &uvs[0][0]);
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 3, GL_REAL, GL_FALSE, 0, &vertexNormals[0][0]);
}
else
{
float speccolor[4] = { 1.0, 1.0, 1.0, 1.0 };
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, color);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, speccolor);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100.0);
glColor3fv(color);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_REAL, 0, &pd.getPosition(0)[0]);
glTexCoordPointer(2, GL_REAL, 0, &uvs[0][0]);
glNormalPointer(GL_REAL, 0, &vertexNormals[0][0]);
}
glDrawElements(GL_TRIANGLES, (GLsizei)3 * mesh.numFaces(), GL_UNSIGNED_INT, mesh.getFaces().data());
if (MiniGL::checkOpenGLVersion(3, 3))
{
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
}
else
{
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
MiniGL::unbindTexture();
}
}
#endif