GLFW: input & timeGLFW 1.0
glfwSetMouseButtonCallback
Registers a function called once each time a mouse button goes down or comes up.
Signature
GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback);
How it works
The callback receives the window, button (GLFW_MOUSE_BUTTON_LEFT…), action (GLFW_PRESS or GLFW_RELEASE) and mods (Shift, Ctrl… held at that moment). It does not receive the position: read it with glfwGetCursorPos inside the callback.
Parameters
windowGLFWwindow*
The window to listen to.
callbackGLFWmousebuttonfun
Your function, void f(GLFWwindow* window, int button, int action, int mods), or NULL.
Return value
The callback that was set before, or NULL.
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GLFW_NOT_INITIALIZED
- Called before glfwInit or after glfwTerminate.
Example
example.cpp
1glfwSetMouseButtonCallback(window, [](GLFWwindow* w, int button, int action, int) {
2 if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
3 double x, y;
4 glfwGetCursorPos(w, &x, &y);
5 pickObjectAt(x, y);
6 }
7});