最小无窗口 OpenGL 上下文初始化

2021-12-19 00:00:00 opengl c++ wgl

如何用最少的代码初始化一个无窗口的 OpenGL 上下文?

How can I initialize a windowless OpenGL context with the minimal amount of code?

我读过这里,您可以使用wglCreateContextAttribsARB创建无窗口上下文,但它没有解释如何?

I've read here that you can use wglCreateContextAttribsARB to create windowless context, however it doesn't explain how?

推荐答案

来自链接:

创建一个没有窗口的上下文,用于离屏渲染.这实际上可能行不通.

Creating a context without a window, for off-screen rendering. This may not actually work.

第二句话很重要.来自 WGL_ARB_create_context 规范:

That second sentence is important. From the WGL_ARB_create_context specification:

4) 是否应该有一种方法可以在不绑定的情况下使上下文成为当前上下文它可以同时绘制到一个窗口系统?

4) Should there be a way to make a context current without binding it to a window system drawable at the same time?

已解决:是的,但仅限于 OpenGL 3.0 及更高版本.这导致一个具有无效默认帧缓冲区的上下文,其含义是在 OpenGL 3.0 规范中定义.

RESOLVED: Yes, but only in OpenGL 3.0 and later. This results in a context with an invalid default framebuffer, the meaning of which is defined in the OpenGL 3.0 specification.

注意:显然在 Windows 上,opengl32.dll 使用了 drawable参数来标识驱动程序的命名空间,所以我们可能不会能够解决它.

NOTE: Apparently on Windows, opengl32.dll makes use of the drawable argument to identify the namespace of the driver, so we may not be able to work around it.

规范不允许您在没有窗口的情况下创建上下文,因为它需要您在设备上下文中设置的像素格式.但是理论上可以在使上下文成为当前上下文时为 HDC 传递 NULL,这会导致 OpenGL 没有默认帧缓冲区.

The specification doesn't allow you to create a context without a window, since it needs the pixel format that you set into the device context. But you theoretically can pass NULL for the HDC when making the context current, which causes OpenGL to not have a default framebuffer.

但是,如上所述,这实际上可能不起作用.你可以试试看会发生什么,但我不会抱有希望.

But, as noted above, this may not actually work. You can try it to see what happens, but I wouldn't get my hopes up.

相关文章