我刚开始使用 glfw 来尝试构建游戏。我对 C 和 C++ 还很陌生,但我之前在 android 上使用过 openGL。我已经完成了所有 openGL 的工作,现在开始尝试使用 glfw 制作线程。
这是一些基本的测试代码。它类似于文档中的内容。
#include <GL/glfw.h>
#include <stdio.h>
GLFWthread thread;
void GLFWCALL testThread()
{
printf("hello\n");
}
int main()
{
printf("test\n");
glfwInit();
thread = glfwCreateThread(testThread, NULL);
glfwWaitThread(thread, GLFW_WAIT);
glfwTerminate();
return 1;
}
这将在 gcc 中编译并按预期工作。
$ gcc -o glthread glthread.c -lglfw
$ ./glthread
test
hello
问题是我想利用 c++ 功能,比如类是我的游戏。当我在 g++ 中编译时,我得到了这个......
$ g++ -o glthread glthread.c -lglfw
glthread.c: In function ‘int main()’:
glthread.c:18: error: invalid conversion from ‘void (*)()’ to ‘void (*)(void*)’
glthread.c:18: error: initializing argument 1 of ‘GLFWthread glfwCreateThread(void (*)(void*), void*)’
当我把它放在课堂上时,关键错误会变成这样。
error: argument of type ‘void (Renderer::)()’ does not match ‘void (*)(void*)’
我基本上想知道的是,是否可以在 c++ 中使用 glfw 创建线程,如果可以,如何?
我用于此工作的主要 PC 是 Arch linux 机器。我现在不能给出我的编译器的版本。如果有帮助,我以后可以得到它们。