GLFW3 Mouse Wheel support

Monkey Targets Forums/Desktop/GLFW3 Mouse Wheel support

DeadFall(Posted 2015) [#1]
Since GLFW3 changed how it handles the mouse wheel calls does anyone have a working example of how to use the updated version?


DeadFall(Posted 2015) [#2]
I've been messing around with some of the code here but to no luck. If anyone has any hints on what can be done that would be really awesome.


ImmutableOctet(SKNG)(Posted 2015) [#3]
For one thing, please keep in mind that this functionality (In the form described in your image) is GLFW3-only. On top of that, unless you want to hack this into Mojo, you'll need to make your code use external code directly, which may not be ideal.

Okay, so you need to use a call-back function. But before that, we need to get the 'GLFWwindow' instance. This isn't possible on GLFW2 (As far as I know, the earlier version that's used by Monkey doesn't have this), so you'll be forced to GLFW3's multi-window ready system. Basically, you'll need to use the GLFW3 version of 'BBGlfwGame', and its 'GetGLFWwindow' command.

To do this, you'd write this (C++ code, GLFW3 only):
BBGlfwGame.GlfwGame().GetGLFWwindow()


Here's the 'GLFWscrollfun' function-pointer type (Used for call-backs) as described by the official documentation. Basically, you'd use 'glfwSetScrollCallback' on the 'GLFWwindow' instance retrieved using the code above. The other argument needs to be a function with the same structure as the 'GLFWscrollfun' pointer-type. From there, you'd simply store the result(s) as you see fit, and access them from Monkey using external bindings.

Here's a small GitHub repository to get you started. It's pretty rough, but it should compile. Also take note of what I did to hack this in with my native code; I inherit 'Object', just so it compiles. That wasn't exactly the best option, but I wasn't really going to bother writing a wrapper system. For the record, my example does not provide differentials, it provides "offsets" (As GLFW calls them), so you'd need to write a simple "CurrentY-LastY" system for positional differences.

If that doesn't help you, then I'm sure there are alternatives here on the forum.

EDIT: In case you're interested, I think Diddy also has scroll-wheel functionality.

It would be great to properly have this through Mojo, though.


DeadFall(Posted 2015) [#4]
Thank you Immutable! Saved me a lot of time yet again. Works perfectly for what I need it to do. And since I was already using a current-last type setup for my stuff with glfw2 it was basically just plug in everything and add a little added change. After each loop need to make sure you set the wheel.YOffset = 0 since I noticed the wheel values only goes up to 2, -2.

That was the last thing that was preventing me from moving fully into GLFW3.

Again thanks!