Use glfwSetWindowUserPointer() to associate your wrapper pointer to the window before you register your callback. When your callback is called, you can use glfwGetWindowUserPointer() to retrieve it.
glfwSetWindowUserPointer()定义在window.c
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow* handle, void* pointer)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT();
window->userPointer = pointer;
}
GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow* handle)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
assert(window != NULL);
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
return window->userPointer;
通过glfwSetWindowUserPointer()把需要的data以指针的方式传递给window。
当需要在callBack函数中获取data时,调用glfwGetWindowUserPointer()

本文介绍如何使用glfwSetWindowUserPointer()将自定义数据指针与窗口关联,以便在回调函数中通过glfwGetWindowUserPointer()检索。这种方法避免了在回调函数参数中显式传递数据的需要。
1574

被折叠的 条评论
为什么被折叠?



