开发者

OpenGL getting perspective pixel data

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜