1
votes

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?

1

1 Answers

3
votes

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.