7
7
#include " SPlisHSPlasH/TriangleMesh.h"
8
8
9
9
#ifdef USE_DOUBLE
10
- #define glNormal3v glNormal3dv
11
- #define glVertex3v glVertex3dv
12
- #define glVertex3 glVertex3d
13
- #define glMultMatrix glMultMatrixd
14
- #define glGetRealv glGetDoublev
15
- #define glLoadMatrix glLoadMatrixd
16
- #define glTranslate glTranslated
17
10
#define GL_REAL GL_DOUBLE
11
+ #define glVertexAttrib3r glVertexAttrib3d
12
+ #define glVertexAttrib3rv glVertexAttrib3dv
18
13
#else
19
- #define glNormal3v glNormal3fv
20
- #define glVertex3v glVertex3fv
21
- #define glVertex3 glVertex3f
22
- #define glMultMatrix glMultMatrixf
23
- #define glGetRealv glGetFloatv
24
- #define glLoadMatrix glLoadMatrixf
25
- #define glTranslate glTranslatef
26
14
#define GL_REAL GL_FLOAT
15
+ #define glVertexAttrib3r glVertexAttrib3f
16
+ #define glVertexAttrib3rv glVertexAttrib3fv
27
17
#endif
28
18
29
19
struct GLFWwindow ;
30
- typedef class GLUquadric GLUquadricObj;
31
20
32
21
namespace SPH
33
22
{
@@ -93,6 +82,9 @@ namespace SPH
93
82
static std::vector<MouseWheelFct> m_mouseWheelFct;
94
83
static int m_width;
95
84
static int m_height;
85
+ static int m_windowWidth;
86
+ static int m_windowHeight;
87
+ static Real m_devicePixelRatio;
96
88
static Vector3r m_translation;
97
89
static Quaternionr m_rotation;
98
90
static Real m_zoom;
@@ -118,10 +110,23 @@ namespace SPH
118
110
static int m_context_profile;
119
111
static bool m_breakPointActive;
120
112
static bool m_breakPointLoop;
121
- static GLUquadricObj* m_sphereQuadric;
122
113
static GLFWwindow* m_glfw_window;
123
114
static bool m_vsync;
124
115
static double m_lastTime;
116
+ static Shader m_shader;
117
+ static Shader m_shader_screen;
118
+ static Matrix4r m_modelview_matrix;
119
+ static Matrix4r m_projection_matrix;
120
+ static Vector3f m_ambientIntensity;
121
+ static unsigned int m_numLights;
122
+ static VectorXf m_diffuseIntensity;
123
+ static VectorXf m_specularIntensity;
124
+ static VectorXf m_lightPosition;
125
+ static GLuint m_vao;
126
+ static GLuint m_vbo_vertices;
127
+ static GLuint m_vbo_normals;
128
+ static GLuint m_vbo_texcoords;
129
+ static GLuint m_vbo_faces;
125
130
126
131
static void reshape (GLFWwindow* glfw_window, int w, int h);
127
132
static void keyboard (GLFWwindow* window, int key, int scancode, int action, int mods);
@@ -139,7 +144,7 @@ namespace SPH
139
144
static void drawVector (const Vector3r &a, const Vector3r &b, const float w, float *color);
140
145
/* * Renders a closed cylinder between two points.
141
146
*/
142
- static void drawCylinder (const Vector3r &a, const Vector3r &b, const float *color, const float radius = 0.02 , const unsigned int subdivisions = 8 );
147
+ static void drawCylinder (const Vector3r &a, const Vector3r &b, const float *color, const float radius = 0.02 , const unsigned int subdivisions = 8 , const bool lighting = true );
143
148
static void drawSphere (const Vector3r &translation, float radius, float *color, const unsigned int subDivision = 16 );
144
149
static void drawQuad (const Vector3r &a, const Vector3r &b, const Vector3r &c, const Vector3r &d, const Vector3r &norm, float *color);
145
150
/* * Draw a tetrahedron.
@@ -174,6 +179,7 @@ namespace SPH
174
179
static void setSelectionFunc (void (*func) (const Vector2i&, const Vector2i&, void *), void *clientData);
175
180
static void setMouseMoveFunc (int button, void (*func) (int , int , void *));
176
181
static void unproject (const int x, const int y, Vector3r &pos);
182
+ static void unproject (const Vector3r& win, Vector3r& pos);
177
183
static float getZNear ();
178
184
static float getZFar ();
179
185
static void hsvToRgb (float h, float s, float v, float *rgb);
@@ -199,6 +205,7 @@ namespace SPH
199
205
200
206
static int getWidth () { return m_width; }
201
207
static int getHeight () { return m_height; }
208
+ static Real getDevicePixelRatio () { return m_devicePixelRatio; }
202
209
203
210
static int getDrawMode () { return drawMode; }
204
211
static void setDrawMode (int val) { drawMode = val; }
@@ -217,6 +224,51 @@ namespace SPH
217
224
static void setWindowSize (int w, int h);
218
225
static bool getWindowMaximized ();
219
226
static void setWindowMaximized (const bool b);
227
+
228
+ static const Matrix4r& getModelviewMatrix () { return m_modelview_matrix; }
229
+ static const Matrix4r& getProjectionMatrix () { return m_projection_matrix; }
230
+
231
+ static void initShaders (const std::string& shaderPath);
232
+ static void destroyShaders ();
233
+ static void enableShader (const Vector3f& ambientReflectance, const Vector3f& diffuseReflectance, const Vector3f& specularReflectance, const float shininess, const float pointSize=1.0 );
234
+ static void disableShader ();
235
+ static void enableScreenShader (const Vector3f& color);
236
+ static void disableScreenShader ();
237
+
238
+ static const GLuint getVao () { return m_vao; }
239
+ static const GLuint getVboVertices () { return m_vbo_vertices; }
240
+ static const GLuint getVboNormals () { return m_vbo_normals; }
241
+ static const GLuint getVboTexcoords () { return m_vbo_texcoords; }
242
+ static const GLuint getVboFaces () { return m_vbo_faces; }
243
+
244
+ // Fill a VBO with vector data and map to the VAO attribute at the specified index.
245
+ static void supplyVectors (GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const float * data);
246
+ static void supplyVectors (GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const double * data);
247
+ // Fill the dedicated VBO with 3D vertex data and map to the VAO attribute at the specified index.
248
+ template <typename T>
249
+ static void supplyVertices (GLuint index, unsigned int numVectors, const T* data)
250
+ {
251
+ supplyVectors (index, m_vbo_vertices, 3 , numVectors, data);
252
+ }
253
+ // Fill the dedicated VBO with 3D normal data and map to the VAO attribute at the specified index.
254
+ template <typename T>
255
+ static void supplyNormals (GLuint index, unsigned int numVectors, const T* data)
256
+ {
257
+ supplyVectors (index, m_vbo_normals, 3 , numVectors, data);
258
+ }
259
+ // Fill the dedicated VBO with 2D texcoord data and map to the VAO attribute at the specified index.
260
+ template <typename T>
261
+ static void supplyTexcoords (GLuint index, unsigned int numVectors, const T* data)
262
+ {
263
+ supplyVectors (index, m_vbo_texcoords, 2 , numVectors, data);
264
+ }
265
+ // Fill a VBO with index data.
266
+ static void supplyIndices (GLuint vbo, unsigned int n, const unsigned int * data);
267
+ // Fill the dedicated VBO with face index data.
268
+ static void supplyFaces (unsigned int numIndices, const unsigned int * data)
269
+ {
270
+ supplyIndices (m_vbo_faces, numIndices, data);
271
+ }
220
272
};
221
273
}
222
274
0 commit comments