JuliaGL / GLFW.jl

Julia interface to GLFW, a multi-platform library for creating windows with OpenGL contexts and managing input and events.
http://www.glfw.org/
MIT License
138 stars 32 forks source link

GLFW.SetWindowUserPointer/GLFW.GetWindowUserPointer #206

Closed Mark-Bowers closed 4 years ago

Mark-Bowers commented 4 years ago

I would like to be able to have access to glfwSetWindowUserPointer and glfwGetWindowUserPointer to avoid having to access a global, variable that contains the application context, from my callback functions. Unfortunately these functions have been appropriated the GLFW package as a way to keep track of a window's registered callbacks.

Is there any interest in a PR that supports the GLFW.SetWindowUserPointer/GLFW.GetWindowUserPointer APIs?

jayschwa commented 4 years ago

Sure, as long as it doesn't mess up callbacks or make them slow. I imagine the way to do it is nest the callbacks and optional application pointer into an object, and the pointer to that parent object is what gets attached to the GLFW window.

Mark-Bowers commented 4 years ago

Thanks, that was the exact approach I had in mind. I'll give it a try.

Mark-Bowers commented 4 years ago

It turns out I don't need these functions after all. I am now using the following technique:

GLFW.SetKeyCallback(s.window, (w,k,sc,a,m)->keyboard(s,w,k,sc,a,m))

where s is my context parameter and a local variable in the function that I am calling SetKeyCallback from and keyboard is my callback function.