PDA

View Full Version : Need Example of glReadPixels function



xbedden
01-09-2004, 11:34 AM
hi ,
first :
if i wrote
GLfloat array[3];
glReadPixels(30,30,1,1,GL_RGB,GL_FLOAT, array);

does this mean that array contains the color information of x=30 and y =30 ??

second :
i colored the pixel at glVertex2i(30,30)
with black color , but when i used glReadPixels to read the color of this point
it does not return the black values of RGB.

anyways : is there a difference between the screen (30,30) and framebuffer (30,30) if so please supply me with some info ..

Best Regards ..
xbedden

Bob
01-09-2004, 12:00 PM
1: Yes, that will read the color of the pixel at (30, 30).

2: Are you sure the projection and modelview matrix is properly set so the point ends up at the pixel you want? An orthographic projection matrix and an identity modelview matirx is a common way to do it.

xbedden
01-09-2004, 03:53 PM
Originally posted by Bob:
1: Yes, that will read the color of the pixel at (30, 30).

2: Are you sure the projection and modelview matrix is properly set so the point ends up at the pixel you want? An orthographic projection matrix and an identity modelview matirx is a common way to do it.


i used :
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800 , 0, 600 , -1.0,1.0);
glMatrixMode(GL_MODELVIEW);

for initializing and the problem is that the glReadPixels returns wrong values

Bob
01-09-2004, 05:25 PM
That projection matrix will not give you an exact one to one mapping between vertex and window coordinates. To hit the center of a pixel, you need to offset the vertex coordinate by 0.5. With integer vertex coordinates, you will hit the corner between four pixels, and depending on rounding errors, any of the four can be the one that gets the point.

So I suggest you offset the projection matrix by -0.5 along both the X and Y axes and see what happens.