Developing on Windows 10, Visual Studio 2015, C++.
I'm a few weeks into my OpenGL experience, a couple of decades into C++.
I have an aversion to globally passed arguments.
Apologies for the length of my first question. When I posted this in the OpenGL forum respondents asked what I wanted to do, what language I was using, and one directed me to this forum. So here is too much information.
Something I'd like to see in any callback function's argument list is a parameter, a void pointer sized (32 or 64 bit) value.
An example would be the parameter you can pass to a Windows dialog procedure.
This is what I'm trying to do
I'm working my way through an exceptional series of OpenGL tutorials at learnopengl.com.
The author's done a nice job of encapsulating camera functions into a camera class here, which I've been augmenting as I go through the lessons. I hope I can build this into a tool that serves me as I develop my own OpenGL applications.
I'd like to similarly encapsulate all of the keyboard, mouse, scroll wheel and other device interfaces found in this code example, from the definition of key_callback() down, into a class I can conveniently add to other projects.
I believe the obstacle that prevents me from wrapping these functions into a nice class is the lack of a parameter argument for functions like glfwSetKeyCallback() and callback functions conforming to GLFWkeyfun.
Pointers to class functions aren't allowed. But if callback functions could have a parameter pointing to the instance of a class then, I believe, a call to that class callback function could work like this:
typedef class CAMERA_WRAPPER_BASIC
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode)
Usefull stuff, with access to class variables
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode,
CAMERA_WRAPPER_BASIC_PTR(parameter)->key_callback(window, key, scancode, action,
So the callback will be a very simple non class function that uses it's parameter as a pointer to the instance of the class, and calls the desired class function that has access to all of the class variables.
glfwSetKeyCallback() has no problem referring to key_callback() because it's not a class function.
Does any of this make sense? Is this something anybody should want to do?
Parameters aren't available for callbacks, directly.
Is there a way to rig this, to make GLFW do something GLFW doesn't want to do?
Again, I'd like to avoid passing global variables.
And again, sorry for the length of my first post.