PDA

View Full Version : glReadPixels, read area out of windows bounds and glFrustum correcting coordinates.



hockeyman
07-26-2012, 03:03 AM
1st problem:

I have app for painting on images. If user loads big image (witch is too big to fit window), the image is being moved more far away at z-axis to fit it. But when image is moved in z-axis my app is not painting as it should. It paints in wrong place. Here's image witch should describe my problem more clearly:

1. Image was moved by glTranslatef(0.0,0.0,-0.5);. Red circle shows where mouse was pressed and the blue where it was drawn.
821

2. Image zoomed to actual size ( glTranslatef(0.0,0.0,-0.1); ). Red circle shows that thing, witch we drawn in first image.
822

As you see drawn point in actual size is exactly in the same position of window where we pressed when image was zoomed out. So I guess OpenGL is listening to window coordinates, or something like that, and doesn't translates coordinates when it zoomed out.

Location's is being registered by:

location = [self convertPoint: [event locationInWindow] fromView:openGLView];

Any solutions?

2nd problem:

I nead glReadPixels to read OpenGL area witch is out of bounds of my window. As described above, image is being "resized" (textured quad is being drawn proportionally smaller) if its too big to fit to window. And user can get back to actual size. If he is back, and I do "save", then in saved image is visible only small part of edited image (only part witch was visible in window and because image was large, when in actual size mode, user can't see everything in window), and other part is just black color. Image:

App window looks like this
823

saved image (original image witch was edited is 3200x200, saved image size is exactly same size as original, just really doesn't looks like it should.).
824


Can anyone suggest me solution?

V-man
07-26-2012, 05:50 AM
I don't know what the first problem is.
For the second, if you need to create a render buffer. You can make it bigger than your viewport.
http://www.opengl.org/wiki/Framebuffer_Objects
http://www.opengl.org/wiki/Framebuffer_Object_Examples
You should look at #6, Quick example, render_to_buffer (p-buffer replacement)

hockeyman
07-30-2012, 03:38 AM
Thank you, i will try it just right now. And I'm still looking for solution for my first problem