OpenGL -- glfwSetWindowUserPointer()

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

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.

 https://stackoverflow.com/questions/27596861/give-static-function-access-to-data-without-passing-the-data-as-a-parameter

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值