OpenGL获取透视像素数据
我正在对包含各种对象的大区域进行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用诸如 gluPerspective 之类的工具将视点设置为所需的矩形,然后渲染场景,并使用 glReadPixels 获取结果。这将为您提供一个像素值矩形 - 您可以将它们转换为您选择的图像格式。
如果您只想要一张静态图片,这可能是最简单的方法。如果您需要/想要更频繁地执行此操作(例如,您确实想要看起来像视频的东西),您可以考虑将其设置为渲染到纹理或帧缓冲区对象。这将(至少通常)提高效率,但会增加额外的复杂性。
You could use something like
gluPerspective
to set your viewpoint to the desired rectangle, then render the scene, and useglReadPixels
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.