ybenaabud

02-23-2004, 03:35 AM

Hi,

I am trying to get the depth of some pixels in my screen. for this I use glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&pixel);

it is good for the first and last plan (0.0 and 1.0), rigth values!

but for intermidiate values I am having some troubles... http://www.opengl.org/discussion_boards/ubb/smile.gif

for exemple:

I put a lookat at (1000,0,0,0,0,0,0,0,1)

I put three triangles perpenducular to X axis. the first at (x=0) the 2nd at (x=100) and the 3rd at (x=200). and I get the depth of three pixels each one inside one of the triangles.

when I multiplie by scale, add bias and map to the range...etc. I shoud have the depth equal to the x coord of the point.

I don't have this and more (depth pt1 + depth pt3)/2 isn't equal to depth2.

this means that the values are not linear !!??

here is the code:

...

glViewport(0,0,500,500);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(90,1.,800,2000);

...

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(1200,0,0,0,0,0,0,0,1);

//for the 1 point I draw this triangle

glBegin(GL_TRIANGLES);

glVertex3f(0, 0 , 50);

glVertex3f(0, 25,-25);

glVertex3f(0,-25,-25);

glEnd();

//for the 2 point I draw this triangle

glBegin(GL_TRIANGLES);

glVertex3f(100, 0 , 50);

glVertex3f(100, 25,-25);

glVertex3f(100,-25,-25);

glEnd();

//for the 3 point I draw this triangle

glBegin(GL_TRIANGLES);

glVertex3f(200, 0 , 50);

glVertex3f(200, 25,-25);

glVertex3f(200,-25,-25);

glEnd();

(of course one triangle each time,and I get the depht of the point that match (y==0 and z==0)

...

//then I use this to get the depth

glReadPixels(xc, yc, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pixel);

//I tried with GL_INSIGNED_INT and is the same!!!

please help !!!

think you

I am trying to get the depth of some pixels in my screen. for this I use glReadPixels(x,y,1,1,GL_DEPTH_COMPONENT,GL_FLOAT,&pixel);

it is good for the first and last plan (0.0 and 1.0), rigth values!

but for intermidiate values I am having some troubles... http://www.opengl.org/discussion_boards/ubb/smile.gif

for exemple:

I put a lookat at (1000,0,0,0,0,0,0,0,1)

I put three triangles perpenducular to X axis. the first at (x=0) the 2nd at (x=100) and the 3rd at (x=200). and I get the depth of three pixels each one inside one of the triangles.

when I multiplie by scale, add bias and map to the range...etc. I shoud have the depth equal to the x coord of the point.

I don't have this and more (depth pt1 + depth pt3)/2 isn't equal to depth2.

this means that the values are not linear !!??

here is the code:

...

glViewport(0,0,500,500);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(90,1.,800,2000);

...

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);

glLoadIdentity();

gluLookAt(1200,0,0,0,0,0,0,0,1);

//for the 1 point I draw this triangle

glBegin(GL_TRIANGLES);

glVertex3f(0, 0 , 50);

glVertex3f(0, 25,-25);

glVertex3f(0,-25,-25);

glEnd();

//for the 2 point I draw this triangle

glBegin(GL_TRIANGLES);

glVertex3f(100, 0 , 50);

glVertex3f(100, 25,-25);

glVertex3f(100,-25,-25);

glEnd();

//for the 3 point I draw this triangle

glBegin(GL_TRIANGLES);

glVertex3f(200, 0 , 50);

glVertex3f(200, 25,-25);

glVertex3f(200,-25,-25);

glEnd();

(of course one triangle each time,and I get the depht of the point that match (y==0 and z==0)

...

//then I use this to get the depth

glReadPixels(xc, yc, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &pixel);

//I tried with GL_INSIGNED_INT and is the same!!!

please help !!!

think you