据我所知,没有跨平台的方式来创建上下文,您将不得不创建自己的抽象,然后为每个平台实现它。
在Windows下我用下面的代码来创建第二个方面做的内容加载在后台线程(使用GLFW这个计划,但认为不应该的问题):
void Program::someFunction()
{
HDC hdc = wglGetCurrentDC();
HGLRC hglrc = wglGetCurrentContext();
HGLRC hglrc_new = wglCreateContext(hdc);
wglShareLists(hglrc, hglrc_new);
loadThread = boost::thread(&Program::loadFunc, this, hdc, hglrc_new);
}
/**
* Imports all our assets. Supposed to run in its own thread with its own OpenGL context.
* @param hdc The current device context.
* @param hglrc A OpenGL context thats shares its display list with the main rendering context.
*/
void Program::loadFunc(HDC hdc, HGLRC hglrc)
{
wglMakeCurrent(hdc, hglrc);
//Do stuff...
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hglrc);
}
这是对的,我假设使用FBO。但FBO不会创建GL环境,这就是为什么我问这个问题。 –
如果您想要硬件加速,至少在Windows上,您不能创建一个OpenGL上下文,而无需先创建(隐藏)窗口。这是因为[wglCreateContext](http://msdn.microsoft.com/en-us/library/windows/desktop/dd374379(v = vs.85).aspx)需要Device Context(DC),并且只有一个窗口的DC可以分配硬件加速像素格式。尤其是,[无法使用硬件加速OpenGL将其渲染到内存DC中](http://www.opengl.org/discussion_boards/showthread.php/161374-Why-can-ti-write-to-a-memory-device -context p = 1143832&viewfull = 1#post1143832)。 – sschuberth
那么你是说LWJGL中的Windows版本的PBuffer会创建窗口,然后删除它? –