hockeyman
hockeyman

Reputation: 1183

glReadPixels read "out of frames" area

I draw OpenGL 3200x2000 size textured quads. OpenGLView frame size is set to 940x560. It draws quad as it should. Bun when I try to save it as image (using glReadPixels) and set glReadPixels area from (0,0) to (3200,2000). It creates pixel data 3200x2000, but when I save it to file I see small image part (940x560 from bottom left corner) and whole other area is black. So how can I read offscreen area? I tried using Framebuffer, but its very complicated, errors while creating it and etc... Is there any other solution?


Situation visualization:

Original image looks like this (3200x2000): enter image description here

OpenGLView looks like this (940x560): enter image description here

Saved image looks like that (3200x2000): enter image description here

Upvotes: 0

Views: 1007

Answers (2)

M-V
M-V

Reputation: 5237

You haven't given much details in terms of code, or the platform.

But I think you should be using offscreen rendering, rather than just reading from the rendered window. If you are unfamiliar with using frame buffer objects, here is a minimal example:

https://github.com/datenwolf/codesamples/tree/master/samples/OpenGL/minimalfbo

Edit #1:

Since OP mentioned that the platform is OS X, I am posting my code below, which shows a minimal FBO example in iOS:

https://github.com/glman74/simpleFBO

Upvotes: 1

Nicol Bolas
Nicol Bolas

Reputation: 473437

So you're rendering to the window. Well, the window has a particular size. And nothing exists outside of that size.

This is part of something OpenGL calls the "pixel-ownership-test". If a pixel is not owned by the context, then its contents are undefined. Pixels outside of the window are not owned by the context, and therefore their contents are undefined.

This is one reason why framebuffer objects exist: so that you can render outside the size of your window. Though be advised: there is a maximum viewport size limit.

Alternatively, you can render in screen-sized pieces, where you download each piece after each rendering, then move the camera to render the next piece.

Upvotes: 4

Related Questions