OpenGL获取透视像素数据

发布于 2024-09-07 16:24:00 字数 169 浏览 5 评论 0原文

我正在对包含各种对象的大区域进行 3D 渲染。我的程序从高角度看待这个领域。

我需要访问(仅)字段中从上方查看的矩形的像素数据。我在字段中有这个矩形的坐标,并且想: (a) 找到与我想要的矩形相对应的像素。 (b)(理想情况下)将相应的像素矩阵写入文件。

有谁知道一个简单的方法来做到这一点?

I am working with a 3D rendering of a large field containing various objects. My program views this field in perspective from a high point.

I need to access the pixel data of (only) a rectangle in the field as viewed from above. I have the coordinates of this rectangle in the field, and would like to:
(a) Find the pixels corresponding to my desired rectangle.
(b) (Ideally) write the corresponding pixel matrix to a file.

Does anyone know a simple way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风流物 2024-09-14 16:24:00

您可以使用诸如 gluPerspective 之类的工具将视点设置为所需的矩形,然后渲染场景,并使用 glReadPixels 获取结果。这将为您提供一个像素值矩形 - 您可以将它们转换为您选择的图像格式。

如果您只想要一张静态图片,这可能是最简单的方法。如果您需要/想要更频繁地执行此操作(例如,您确实想要看起来像视频的东西),您可以考虑将其设置为渲染到纹理或帧缓冲区对象。这将(至少通常)提高效率,但会增加额外的复杂性。

You could use something like gluPerspective to set your viewpoint to the desired rectangle, then render the scene, and use glReadPixels to get the result back. That will give you a rectangle of pixel values -- it'll be up to you to convert them to an image format of your choice.

If you just want a single, static picture that's probably the simplest way to go. If you need/want to do it more often (e.g., you really want something that looks like a video), you could consider setting it up to render to a texture or a frame buffer object. This will (at least usually) improve efficiency at the expense of extra complexity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文