2

I've been playing with Derelict3&glfw to use OpenGL in D according to this, if I want to use extensions, I need to create a context first, and this is done by creating a window with glfw and set it as the current context. After the context is created and set, I need to use DerelictGL3.reload() to load all the extensions.

Now, I want to do all the preparations before I create the window. One of those preparations is to load and compile all the shader programs. But this required the shader extension, which required Derelict3GL.reload(), which refuses to run without a context...

So, I've used this hackish hack:

auto tmpWindow=glfwCreateWindow(1,1,"",null,null);
glfwMakeContextCurrent(tmpWindow);
DerelictGL3.reload();
glfwDestroyWindow(tmpWindow);

This works - I can now load and compile the shader programs and only then open the real window. But this seems a bit too hackish to me. Is there a proper way to fake a context, or to load the extensions without a context?

4

1 回答 1

3

是否有适当的方法来伪造上下文,或者在没有上下文的情况下加载扩展?

这取决于平台:

使用 Windows:通过中间窗口(不必在屏幕上可见地映射)执行此操作是在 Windows 上可靠地加载扩展的唯一方法。

使用 X11/GLX:扩展函数指针可以使用 glXGetProcAddress 立即加载,扩展函数是 GLX 客户端库的一部分,对所有上下文都是通用的。但是,实际的 OpenGL 上下文可能不支持可以使用 glXProcAddress 有效获取的所有函数。

于 2013-05-01T23:32:17.407 回答