In GLFW, there is something known as a User Pointer and I can set it with glfwSetWindowUserPointer. What I don't know is a User Pointer. This is my guess. A user pointer is a pointer to the user that uses the window. Am I correct or am I wrong?
Firstly, it's unrelated to OpenGL. As glfw
prefix shows, the function is from GLFW.
That "user pointer" is just an arbitrary pointer associated with a window. You can read and write it, and GLFW otherwise ignores it.
It is a way to pass additional information into various GLFW callbacks. Let's say you create a "window" class to wrap GLFWwindow
, and want to interact with an instance of it from GLFW callbacks. Then you could make the "user pointer" point to it (the only alternative to that is to make it a global variable).
Most C libraries that use callbacks do this. Normally you get one pointer per callback, but GLFW does one per window.
C++ libraries don't tend to do this, since if std::function
is used for a callback, it lets you add arbitrary state to the callback (e.g. it can store lambas with catpure, while a function pointer can't).
© 2022 - 2024 — McMap. All rights reserved.