@@ -38,6 +38,7 @@ class OpenGLWindow {
38
38
glfwSetKeyCallback (window, key_callback);
39
39
glfwSetWindowCloseCallback (window, close_callback);
40
40
glfwSetFramebufferSizeCallback (window, resize_callback);
41
+ glfwSetCursorPosCallback (window, mouse_callback);
41
42
42
43
if (glewInit () != GLEW_OK) {
43
44
glfwTerminate ();
@@ -74,6 +75,10 @@ class OpenGLWindow {
74
75
cout << endl;
75
76
}
76
77
78
+ GLFWwindow* getGLFWwindow () {
79
+ return window;
80
+ }
81
+
77
82
private:
78
83
79
84
static void error_callback (int error, const char * description)
@@ -99,6 +104,12 @@ class OpenGLWindow {
99
104
win_app->onresize (width, height);
100
105
}
101
106
107
+ static void mouse_callback (GLFWwindow* window, double xpos, double ypos)
108
+ {
109
+ OpenGLWindow* win_app = getOpenGLWinApp (window);
110
+ win_app->onmouse (xpos, ypos);
111
+ }
112
+
102
113
inline static OpenGLWindow* getOpenGLWinApp (GLFWwindow* window) {
103
114
return static_cast <OpenGLWindow*>(glfwGetWindowUserPointer (window));
104
115
}
@@ -111,6 +122,8 @@ class OpenGLWindow {
111
122
virtual void onkey (int key, int scancode, int action, int mods) { };
112
123
113
124
virtual void onrender (double time) = 0;
125
+
126
+ virtual void onmouse (double xpos, double ypos) { };
114
127
115
128
virtual void onresize (int width, int height) {
116
129
aspect_ratio = max (0 .0f , width / (float )height);
0 commit comments