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,22 @@ 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_faces;
125
129
126
130
static void reshape (GLFWwindow* glfw_window, int w, int h);
127
131
static void keyboard (GLFWwindow* window, int key, int scancode, int action, int mods);
@@ -139,7 +143,7 @@ namespace SPH
139
143
static void drawVector (const Vector3r &a, const Vector3r &b, const float w, float *color);
140
144
/* * Renders a closed cylinder between two points.
141
145
*/
142
- static void drawCylinder (const Vector3r &a, const Vector3r &b, const float *color, const float radius = 0.02 , const unsigned int subdivisions = 8 );
146
+ 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
147
static void drawSphere (const Vector3r &translation, float radius, float *color, const unsigned int subDivision = 16 );
144
148
static void drawQuad (const Vector3r &a, const Vector3r &b, const Vector3r &c, const Vector3r &d, const Vector3r &norm, float *color);
145
149
/* * Draw a tetrahedron.
@@ -174,6 +178,7 @@ namespace SPH
174
178
static void setSelectionFunc (void (*func) (const Vector2i&, const Vector2i&, void *), void *clientData);
175
179
static void setMouseMoveFunc (int button, void (*func) (int , int , void *));
176
180
static void unproject (const int x, const int y, Vector3r &pos);
181
+ static void unproject (const Vector3r& win, Vector3r& pos);
177
182
static float getZNear ();
178
183
static float getZFar ();
179
184
static void hsvToRgb (float h, float s, float v, float *rgb);
@@ -199,6 +204,7 @@ namespace SPH
199
204
200
205
static int getWidth () { return m_width; }
201
206
static int getHeight () { return m_height; }
207
+ static Real getDevicePixelRatio () { return m_devicePixelRatio; }
202
208
203
209
static int getDrawMode () { return drawMode; }
204
210
static void setDrawMode (int val) { drawMode = val; }
@@ -217,6 +223,44 @@ namespace SPH
217
223
static void setWindowSize (int w, int h);
218
224
static bool getWindowMaximized ();
219
225
static void setWindowMaximized (const bool b);
226
+
227
+ static const Matrix4r& getModelviewMatrix () { return m_modelview_matrix; }
228
+ static const Matrix4r& getProjectionMatrix () { return m_projection_matrix; }
229
+
230
+ static void initShaders (const std::string& shaderPath);
231
+ static void destroyShaders ();
232
+ static void enableShader (const Vector3f& ambientReflectance, const Vector3f& diffuseReflectance, const Vector3f& specularReflectance, const float shininess, const float pointSize=1.0 );
233
+ static void disableShader ();
234
+ static void enableScreenShader (const Vector3f& color);
235
+ static void disableScreenShader ();
236
+
237
+ static const GLuint getVao () { return m_vao; }
238
+ static const GLuint getVboVertices () { return m_vbo_vertices; }
239
+ static const GLuint getVboNormals () { return m_vbo_normals; }
240
+ static const GLuint getVboFaces () { return m_vbo_faces; }
241
+
242
+ // Fill a VBO with vector data and map to the VAO attribute at the specified index.
243
+ static void supplyVectors (GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const float * data);
244
+ static void supplyVectors (GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const double * data);
245
+ // Fill the dedicated VBO with 3D vertex data and map to the VAO attribute at the specified index.
246
+ template <typename T>
247
+ static void supplyVertices (GLuint index, unsigned int numVectors, const T* data)
248
+ {
249
+ supplyVectors (index, m_vbo_vertices, 3 , numVectors, data);
250
+ }
251
+ // Fill the dedicated VBO with 3D normal data and map to the VAO attribute at the specified index.
252
+ template <typename T>
253
+ static void supplyNormals (GLuint index, unsigned int numVectors, const T* data)
254
+ {
255
+ supplyVectors (index, m_vbo_normals, 3 , numVectors, data);
256
+ }
257
+ // Fill a VBO with index data.
258
+ static void supplyIndices (GLuint vbo, unsigned int n, const unsigned int * data);
259
+ // Fill the dedicated VBO with face index data.
260
+ static void supplyFaces (unsigned int numIndices, const unsigned int * data)
261
+ {
262
+ supplyIndices (m_vbo_faces, numIndices, data);
263
+ }
220
264
};
221
265
}
222
266
0 commit comments