我刚开始使用glfw来尝试构建一个游戏。我对C和C++相当陌生,但之前我使用openGL处理过Android。我已经拥有了所有的OpenGL工具,现在开始尝试使用glfw创建线程。如何在C++中创建一个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上工作是一个拱Linux机器。我现在无法提供我的编译器版本。如果它能帮助我以后可以得到它们。
谢谢。这是一个简单的修复。它现在非常有意义。我可能不得不像你所建议的那样为线程找到更好的C++库。我只是喜欢在GLFW中做所有事情的想法。 – Lightbulb1