提问人:LondonNight 提问时间:9/21/2023 更新时间:9/21/2023 访问量:19
glfwSetCharCallback 不接受我的函数签名
glfwSetCharCallback not accepting my function signature
问:
制作了一个 GLFW 窗口。尝试设置用户输入。我用(看似)正确的参数调用了“glfwSetCharCallback”。最后一个参数是按下某个键时应调用的函数。我称它为“callbackFun”。“glfwSetCharCallback”不会有任何它,告诉我“callbackFun”具有错误的函数签名。我做错了什么?
int MultiLauncher::run()
{
std::cout << "Begin..." << std::endl;
GLFWwindow* window = initApp();
//character input
glfwSetCharCallback(window, callbackFun);
figure triangle;
/* Game Loop until the user closes the window */
while (!glfwWindowShouldClose(window) && keepRunningGame)
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
triangle.buildFigure();
triangle.drawFigure();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void MultiLauncher::callbackFun(GLFWwindow* window, uint codepoint)
{
std::cout << codepoint << std::endl;
keyEventsInstance.processKey(codepoint);
}
尝试在谷歌上搜索 callbackFun 的正确函数签名,看起来不错,但 glfwSetCharCallback 不会接受它。
答:
0赞
Erdal Küçük
9/21/2023
#1
如果不是静态成员函数,则在后台,签名如下所示MultiLauncher::callbackFun
void MultiLauncher::callbackFun(MultiLauncher* this, GLFWwindow* window, uint codepoint);
这不是 GLFW 预期的函数签名。
只需使成员函数(将关键字放在函数声明的前面),例如static
static
class MultiLauncher {
public:
// static member function declaration
static void callbackFun(GLFWwindow* window, uint codepoint);
};
// function definition
// there is no object (this) associated,
// so, if you need an object, you have to set it somewhere (accessible)
// before this function gets called
void MultiLaucher::callbackFun(GLFWwindow* window, uint codepoint)
{
//...
}
更多信息:
评论