控制台中的 openGL 上下文
我想使用 openGL 的某些功能,但与渲染视觉内容无关。有没有办法在没有任何依赖项的情况下创建它(不依赖于Windows,也不依赖于某些包[SDL,SFML,GLUT])?只允许那些没有外部库的库,就像我使用的 GLEW 一样。
I'd like to use certain functions of openGL, but nothing related to rendering visual content. Is there way to create it without ANY dependencies (not to windows, nor some package[SDL, SFML, GLUT])? Only libraries allowed are those without external libraries, just like GLEW which I use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要做的通常称为离屏渲染。理论上这是完全可能的,但实际实施有很多注意事项。最重要的是,对于所有主要的高性能实现:即使没有可见的渲染窗口,您仍然需要图形系统运行并处于活动状态,并且您的程序在此图形系统的环境中运行。
在 Windows 上,最直接的方法是创建不可见窗口,只是使用 CreateWindowEx 创建但不使用 ShowWindow 映射的窗口;您甚至不需要事件处理循环。在此窗口中,您像往常一样创建 OpenGL 上下文,但不是渲染到窗口帧缓冲区,而是渲染到帧缓冲区对象。
在 X11/GLX 上,情况更加简单:X11/GLX 提供没有扩展的 PBuffer(Windows 也有 PBuffer,但要创建一个,您首先需要一个常规的 OpenGL 上下文)。所以在 X11 上你可以创建一个没有代理窗口的 PBuffer。 PBuffer 本身可以渲染为离屏缓冲区;如果实现支持,帧缓冲区对象也可以在 PBuffer 中工作。使用带有帧缓冲区对象的不可见窗口(就像使用 Windows 一样)也可以。不管怎样,当前的驱动程序 X11 必须处于活动状态并且绑定控制台,因此您不能在后台启动额外的 X 服务器并在那里进行离屏渲染,但这只是一个限制驱动程序的,而不是 X11、GLX 或 OpenGL 的。
您可以将 GLEW 静态链接到您的程序。如果您是铁杆玩家,您可以手动加载扩展程序,但为什么要这样做呢?
What you want to do is known in general as off-screen rendering. In theory it is possible perfectly well, however the practical implementation has a lot of caveats. Most importantly on all major high performance implementations: Even if no rendering window is visible you still need the graphics system running and being active and your program run in the environment of this graphics system.
On Windows the most straightforward way to go is creating invisible window, just a window you create with CreateWindowEx but not map with ShowWindow; you don't even need a event processing loop for that. In this window you create your OpenGL context as usual, but instead of rendering to the window framebuffer, you render to a Frame Buffer Object.
On X11/GLX it's even more straightforward: X11/GLX offers PBuffers without extensions (Windows has PBuffers, too, but for creating one you need a regular OpenGL context first). So on X11 you can create a PBuffer without a proxy window. The PBuffer iteself can be rendered to as off-screen buffer; Frame Buffer Object work in a PBuffer, as well, if the implementation supports them. Using a invisible window with a Frame Buffer Object, just like with Windows, works as well. Either way, with current drivers X11 must be active and the bound console, so you can not start an additional X server in the background and have your off-screen rendering happen there, but this is just a limitation of the drivers and not of X11, GLX or OpenGL.
You can link GLEW statically to your program. If you're hardcore you can do extension loading manually, but why would you want to do that?
你如何定义“最轻”?
除了创建 OpenGL 窗口之外,执行最少操作的两个跨平台库是 FreeGLUT 和 GLFW。
FreeGLUT 有一个大约 5.2MB 的发行版(解压后),而 GLFW 有一个 2.6MB 的发行版。这会让它变得“更轻”吗? FreeGLUT编译的静态库,在VS2008下release模式下,大约500KB;类似编译下的GLFW为120KB。这会让它变得“更轻”吗?
How do you define "lightest?"
The two cross-platform libraries that do the least other than creating OpenGL windows are FreeGLUT and GLFW.
FreeGLUT has about a 5.2MB distribution (after unzipping), while GLFW has a 2.6MB distro. Does that make it "lighter"? FreeGLUT's compiled static library, in release mode under VS2008, is around 500KB; the one for GLFW under similar compilation is 120KB. Does that make it "lighter"?