OpenGL v1.1:离屏渲染或直接渲染位图
我将 OpenGL 与 C# 结合使用,为我们的项目使用 CSGL12 接口。我正在尝试将许多 4 点自由变换图像绘制到内存中的位图上。
有没有办法:
- 直接渲染到内存上的位图,或者
- 渲染到离屏实例,然后将其转换为位图?我需要知道如何设置离屏实例以及转换。
任一方法都必须在远程桌面、虚拟机和 Panasonic CF-19 Toughbook(即 OpenGL v1.1)上运行。如果可能的话,提供与之相关的示例代码将会有很大帮助。
I'm using OpenGL with C#, using CSGL12 interface for our project. I'm attempting to draw a number of 4-point free-transformed images onto a bitmap in memory.
Is there a way to either:
- Directly render to a bitmap on memory, or,
- Render to an off-screen instance, and then convert this to a bitmap? I need to know how to setup an off-screen instance as well as the conversion.
Either method must work on a Remote Desktop, a Virtual Machine, and on a Panasonic CF-19 Toughbook (i.e. OpenGL v1.1). If possible, providing an example code related to it will help tremendously.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要知道,OpenGL-1.1如今确实已经过时了。即使是市场上最蹩脚的 GPU 现在也可以执行 OpenGL-1.4。您首先应该知道的一件事是,OpenGL 被设计用于在屏幕上显示图片,尽管输出后端的性质在规范中保持抽象。如果您想使用 OpenGL 来加速渲染 3D 内容,那么不要渲染为位图。这总是会让您回到软件光栅化模式,该模式非常慢,因此请使用 PBuffer 或 Framebuffer 对象。帧缓冲区对象使用起来很简单。但 PBuffer 有点棘手。
在 Windows 中,您始终需要先绕道创建具有一些 OpenGL 上下文的虚拟窗口,以便您可以请求和使用 OpenGL 扩展。使用 X11/GLX 可以创建一个没有虚拟窗口的 PBuffer。然而,PBuffer 的通常用途是创建动态纹理内容的地方。
以下是我很久以前编写的一些代码,它默默地假定现有的、有效初始化的 OpenGL 上下文在当前线程上处于活动状态,并将配置 PBuffer 上下文以与原始上下文共享其 OpenGL 对象。它还取决于库GLEW。
pbuffer.h
pbuffer.cpp
You know, OpenGL-1.1 is really outdated nowadays. Even the crappiest GPUs on the market can do OpenGL-1.4 now. One thing you should know first is, that OpenGL has been designed for getting pictures on the screen, although the nature of the output backend is keept abstract in the specification. If you want to use OpenGL to render 3D stuff accelerated, then don't render to bitmaps. This will always fall you back into software rasterization mode, which is extremely slow So use a PBuffer or a Framebuffer Object. Framebuffer Objects are straigtforward to use. But PBuffers are a little bit tricky.
In Windows you always need to take a detour over creating a dummy window with some OpenGL context first, so that you can request and use OpenGL extensions. Using X11/GLX one can create a PBuffer without that dummy window. However the usual use for a PBuffer used to be a place where contents for dynamic textures were created.
The following is some code I wrote ages ago, and it silently assumes an existing, validly initialized OpenGL context to be active on the current thread, and will configure the PBuffer context to share its OpenGL objects with the original context. Also it depends on the library GLEW.
pbuffer.h
pbuffer.cpp
您可以使用 Bitmap.LockBits 和 glCopyPixels 从缓冲区(opengl 调用离屏缓冲区“aux”)中提取位图。
You can pull from a buffer (opengl calls off-screen buffers "aux") into a bitmap using
Bitmap.LockBits
andglCopyPixels
.