类内的 GLFW 回调
GLFW callback inside class
这有效: (主要(:
glfwSetCharCallback(window, Console_Input);
(全球(:
void Console_Input(GLFWwindow* window, unsigned int letter_i){
}
如果我试着把它放在课堂上: (主要(:
Input_text Text_Input(&Text_Input_bar, &GLOBALS);
glfwSetCharCallback(window, Text_Input.Console_Input);
(全球(:
class Input_text{
...
void Console_Input(GLFWwindow* window, unsigned int letter_i){
}
void Update(){
if(active == 1){
MBar->Re_set_bar_width(str);
MBar->update_bar();
}
}
};
它不起作用。我收到错误: 无法将"Input_text::Console_Input"从类型"void (Input_text::)(GLFWwindow*, unsigned int("转换为类型"GLFWcharfun {aka void (((GLFWwindow, unsigned int(}" 我不想在回调函数中编写功能。我需要自我管理课程。有没有办法将 glfwSetCharCallback 设置为类中的函数?
回调必须是函数(或静态方法(,但您可以将用户指针关联到GLFWindow
。请参阅glfwSetWindowUserPointer
。
指针可以按glfwGetWindowUserPointer
从GLFWWindow
对象检索
将指向Text_Input
的指针关联到window
:
Input_text Text_Input(&Text_Input_bar, &GLOBALS);
glfwSetWindowUserPointer(window, &Text_Input);
glfwSetCharCallback(window, Console_Input);
从window
获取指针,并将类型为void*
的指针投射到Input_text *
(可悲的是你必须进行强制转换(。
void Console_Input(GLFWwindow* window, unsigned int letter_i)
{
Input_text *ptr= (Input_text *)glfwGetWindowUserPointer(window);
ptr->Console_Input(window, i);
}
void Console_Input(GLFWwindow* window, unsigned int letter_i)
应该是全局函数,它不能是类的成员函数
回答你的问题:不,没有办法把它放在课堂上。
相关文章:
- 架构决策:返回std::future还是提供回调
- 正在为Xtensa simcall函数编写回调函数
- 如何在C++中使用非静态成员函数作为回调函数
- FLTK:按下哪个按钮 - 将数字传递给按钮的回调 (lambda)
- 在简单示例中,Python3 + ctypes 回调会导致内存泄漏
- 用于在回调中调用解析器的设计模式
- 如何使用C++对象的成员函数作为 C 样式回调?
- Java从C++回调到C++回调
- 如何将成员函数作为回调参数传递给需要"typedef-ed"自由函数指针的函数?
- 从不同的 cpp 调用回调函数会导致bad_function_call
- pcap_handler回调仅在使用 NPCAP v0.9991 时包含空数据包
- 不带轮询的 SDL2 事件回调
- C++存储带有可变参数的回调
- 如何使用 Node-addon-API 实现 node-nan 回调
- 处理影响跨不同线程共享对象的定时回调的最佳方法是什么?
- 类内的 GLFW 回调
- 鼠标离开 GLFW窗口后触发 GLFW 鼠标回调?
- 回调函数中的 GLFW 传递了更多的参数,然后是预期的
- GLFW设置回调函数
- 如何多线程glfw键盘回调