Skip to content

Commit c2dc116

Browse files
committed
Port MiniGL to OpenGL 3.3 Core
1 parent b04592e commit c2dc116

File tree

13 files changed

+750
-735
lines changed

13 files changed

+750
-735
lines changed

GUI/OpenGL/MiniGL.cpp

Lines changed: 439 additions & 360 deletions
Large diffs are not rendered by default.

GUI/OpenGL/MiniGL.h

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,14 @@
77
#include "SPlisHSPlasH/TriangleMesh.h"
88

99
#ifdef USE_DOUBLE
10-
#define glNormal3v glNormal3dv
11-
#define glVertex3v glVertex3dv
12-
#define glVertex3 glVertex3d
13-
#define glMultMatrix glMultMatrixd
1410
#define glGetRealv glGetDoublev
15-
#define glLoadMatrix glLoadMatrixd
16-
#define glTranslate glTranslated
1711
#define GL_REAL GL_DOUBLE
1812
#else
19-
#define glNormal3v glNormal3fv
20-
#define glVertex3v glVertex3fv
21-
#define glVertex3 glVertex3f
22-
#define glMultMatrix glMultMatrixf
2313
#define glGetRealv glGetFloatv
24-
#define glLoadMatrix glLoadMatrixf
25-
#define glTranslate glTranslatef
2614
#define GL_REAL GL_FLOAT
2715
#endif
2816

2917
struct GLFWwindow;
30-
typedef class GLUquadric GLUquadricObj;
3118

3219
namespace SPH
3320
{
@@ -93,6 +80,9 @@ namespace SPH
9380
static std::vector<MouseWheelFct> m_mouseWheelFct;
9481
static int m_width;
9582
static int m_height;
83+
static int m_windowWidth;
84+
static int m_windowHeight;
85+
static Real m_devicePixelRatio;
9686
static Vector3r m_translation;
9787
static Quaternionr m_rotation;
9888
static Real m_zoom;
@@ -118,10 +108,22 @@ namespace SPH
118108
static int m_context_profile;
119109
static bool m_breakPointActive;
120110
static bool m_breakPointLoop;
121-
static GLUquadricObj* m_sphereQuadric;
122111
static GLFWwindow* m_glfw_window;
123112
static bool m_vsync;
124113
static double m_lastTime;
114+
static Shader m_shader;
115+
static Shader m_shader_screen;
116+
static Matrix4r m_modelview_matrix;
117+
static Matrix4r m_projection_matrix;
118+
static Vector3r m_ambientIntensity;
119+
static unsigned int m_numLights;
120+
static VectorXr m_diffuseIntensity;
121+
static VectorXr m_specularIntensity;
122+
static VectorXr m_lightPosition;
123+
static GLuint m_vao;
124+
static GLuint m_vbo_vertices;
125+
static GLuint m_vbo_normals;
126+
static GLuint m_vbo_faces;
125127

126128
static void reshape (GLFWwindow* glfw_window, int w, int h);
127129
static void keyboard(GLFWwindow* window, int key, int scancode, int action, int mods);
@@ -139,7 +141,7 @@ namespace SPH
139141
static void drawVector(const Vector3r &a, const Vector3r &b, const float w, float *color);
140142
/** Renders a closed cylinder between two points.
141143
*/
142-
static void drawCylinder(const Vector3r &a, const Vector3r &b, const float *color, const float radius = 0.02, const unsigned int subdivisions = 8);
144+
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);
143145
static void drawSphere(const Vector3r &translation, float radius, float *color, const unsigned int subDivision = 16);
144146
static void drawQuad (const Vector3r &a, const Vector3r &b, const Vector3r &c, const Vector3r &d, const Vector3r &norm, float *color);
145147
/** Draw a tetrahedron.
@@ -174,6 +176,7 @@ namespace SPH
174176
static void setSelectionFunc(void(*func) (const Vector2i&, const Vector2i&, void*), void *clientData);
175177
static void setMouseMoveFunc(int button, void(*func) (int, int, void*));
176178
static void unproject(const int x, const int y, Vector3r &pos);
179+
static void unproject(const Vector3r& win, Vector3r& pos);
177180
static float getZNear();
178181
static float getZFar();
179182
static void hsvToRgb(float h, float s, float v, float *rgb);
@@ -199,6 +202,7 @@ namespace SPH
199202

200203
static int getWidth() { return m_width; }
201204
static int getHeight() { return m_height; }
205+
static Real getDevicePixelRatio() { return m_devicePixelRatio; }
202206

203207
static int getDrawMode() { return drawMode; }
204208
static void setDrawMode(int val) { drawMode = val; }
@@ -217,6 +221,31 @@ namespace SPH
217221
static void setWindowSize(int w, int h);
218222
static bool getWindowMaximized();
219223
static void setWindowMaximized(const bool b);
224+
225+
static const Matrix4r& getModelviewMatrix() { return m_modelview_matrix; }
226+
static const Matrix4r& getProjectionMatrix() { return m_projection_matrix; }
227+
228+
static void initShaders(const std::string& shaderPath);
229+
static void enableShader(const Vector3r& ambientReflectance, const Vector3r& diffuseReflectance, const Vector3r& specularReflectance, const Real shininess, const Real pointSize=1.0);
230+
static void disableShader();
231+
static void enableScreenShader(const Vector3r& color);
232+
static void disableScreenShader();
233+
234+
static const GLuint getVao() { return m_vao; }
235+
static const GLuint getVboVertices() { return m_vbo_vertices; }
236+
static const GLuint getVboNormals() { return m_vbo_normals; }
237+
static const GLuint getVboFaces() { return m_vbo_faces; }
238+
239+
// Fill a VBO with vector data and map to the VAO attribute at the specified index.
240+
static void supplyVectors(GLuint index, GLuint vbo, unsigned int dim, unsigned int n, const Real* data);
241+
// Fill the dedicated VBO with 3D vertex data and map to the VAO attribute at the specified index.
242+
static void supplyVertices(GLuint index, unsigned int numVectors, const Real* data);
243+
// Fill the dedicated VBO with 3D normal data and map to the VAO attribute at the specified index.
244+
static void supplyNormals(GLuint index, unsigned int numVectors, const Real* data);
245+
// Fill a VBO with index data.
246+
static void supplyIndices(GLuint vbo, unsigned int n, const unsigned int* data);
247+
// Fill the dedicated VBO with face index data.
248+
static void supplyFaces(unsigned int numIndices, const unsigned int* data);
220249
};
221250
}
222251

GUI/OpenGL/Selection.h

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111

1212
#ifdef __APPLE__
1313
#include <OpenGL/GL.h>
14-
#include <OpenGL/GLU.h>
1514
#else
1615
#include "GL/gl.h"
17-
#include "GL/glu.h"
1816
#endif
1917

2018
#include <vector>
@@ -44,34 +42,25 @@ namespace SPH
4442
int itop = ip1y > ip2y ? ip1y : ip2y;
4543
int ibottom = ip1y < ip2y ? ip1y : ip2y;
4644

47-
float left = (float)ileft;
48-
float right = (float)iright;
49-
float top = (float)itop;
50-
float bottom = (float)ibottom;
45+
float left = (float)ileft * MiniGL::getDevicePixelRatio();
46+
float right = (float)iright * MiniGL::getDevicePixelRatio();
47+
float top = (float)itop * MiniGL::getDevicePixelRatio();
48+
float bottom = (float)ibottom * MiniGL::getDevicePixelRatio();
5149

5250
if (left != right && top != bottom)
5351
{
5452
GLint viewport[4];
55-
GLdouble mv[16],pm[16];
5653
glGetIntegerv(GL_VIEWPORT, viewport);
57-
glGetDoublev(GL_MODELVIEW_MATRIX, mv);
58-
glGetDoublev(GL_PROJECTION_MATRIX, pm);
5954

60-
GLdouble resx,resy,resz;
6155
float zNear = MiniGL::getZNear();
6256
float zFar = MiniGL::getZFar();
63-
gluUnProject(left, viewport[3] - top, zNear , mv, pm, viewport, &resx, &resy, &resz);
64-
const Vector3r vector0((Real)resx, (Real)resy, (Real)resz);
65-
gluUnProject(left, viewport[3] - top, zFar , mv, pm, viewport, &resx, &resy, &resz);
66-
const Vector3r vector1((Real)resx, (Real)resy, (Real)resz);
67-
gluUnProject(left, viewport[3] - bottom, zNear , mv, pm, viewport, &resx, &resy, &resz);
68-
const Vector3r vector2((Real)resx, (Real)resy, (Real)resz);
69-
gluUnProject(right, viewport[3] - top, zNear , mv, pm, viewport, &resx, &resy, &resz);
70-
const Vector3r vector3((Real)resx, (Real)resy, (Real)resz);
71-
gluUnProject(right, viewport[3] - bottom, zNear , mv, pm, viewport, &resx, &resy, &resz);
72-
const Vector3r vector4((Real)resx, (Real)resy, (Real)resz);
73-
gluUnProject(right, viewport[3] - bottom, zFar , mv, pm, viewport, &resx, &resy, &resz);
74-
const Vector3r vector5((Real)resx, (Real)resy, (Real)resz);
57+
Vector3r vector0, vector1, vector2, vector3, vector4, vector5;
58+
MiniGL::unproject(Vector3r(left, viewport[3] - top, zNear), vector0);
59+
MiniGL::unproject(Vector3r(left, viewport[3] - top, zFar), vector1);
60+
MiniGL::unproject(Vector3r(left, viewport[3] - bottom, zNear), vector2);
61+
MiniGL::unproject(Vector3r(right, viewport[3] - top, zNear), vector3);
62+
MiniGL::unproject(Vector3r(right, viewport[3] - bottom, zNear), vector4);
63+
MiniGL::unproject(Vector3r(right, viewport[3] - bottom, zFar), vector5);
7564

7665
SelectionPlane plane[4];
7766
plane[0].normal = (vector3-vector0).cross(vector1-vector0);

0 commit comments

Comments
 (0)