tomster1996's picture

Creating a 2D image from the current 3D projection

How would I go about retrieving a 2d bitmap of the final result of all the 3D content being drawn to the screen? Is there some sort of view buffer I could use? I don't want to include any 2d images being drawn to the application after the 3D content so the final buffer that includes everything to be drawn to the screen is useless to me.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jdomnitz's picture

CopyPixels after drawing the 3D content and before the 2D content?

the Fiddler's picture

You can use GL.ReadPixels and GL.CopyPixels to retrieve the contents of the front buffer (this is the buffer that is visible on screen). If you don't have a front buffer (because you wish to render to an invisible window) you will have to create and use a framebuffer object.

tomster1996's picture

Using the CopyPixels function is too slow when using it for every process in the game loop. I'm using it for dynamic reflections on water, i could however use CopyPixels on a pre rendered scene and put the bitmapin a file for a static reflection. But how do i actually retrieve the pixels, are they copied to the clipboard or something?

swiftcoder's picture
tomster1996 wrote:

Using the CopyPixels function is too slow when using it for every process in the game loop.

If one doesn't need the results instantly, one typically GL.ReadPixels to a PBO (pixel buffer object), and then reads it back to main memory on the next frame. This avoids stalling the GPU, as happens when you ReadPixels directly to main memory.

Quote:

I'm using it for dynamic reflections on water

The usual approach would be to render the reflections into a texture (using an FBO), and then you can apply that texture to the water directly.

Quote:

But how do i actually retrieve the pixels, are they copied to the clipboard or something?

CopyPixels only copies pixels within the framebuffer, so probably isn't what you are looking for. GL.ReadPixels takes a pointer to a buffer/location in memory, and places the results there, after which you can do what you want with them.