GluPrject GluUnproject and ReadPixel

Could someone tell me what’s wrong here?

I have a 3D object of +/- 500 000 pts and 1000 000 traingle and i would like to be able to define a rectangle on the screen an then say wich point is in the rectangle or not.

But if the object is in real 3D 360° i want only points displayed on the screen not those hiden.


Here is the code :
I just test each point of my model. Find the windows coord of the point treated (with GluProject() then with GlReadPixel() find the winz and then with GluUnProject() find the object coord of the point in windows coord.

If this point is the same that the original point and is in the rectangle ABCD, i keep it.

But the problem is that this doesn’t work i have also the points hidden

// ABCD is a rectangle to define the coord of the windows on the screen we want
A.X = 560; A.Y = 430; B.X = 720; B.Y = 430; C.X = 560; C.Y = 540; D.X = 720; D.Y = 540;

// Point of the mesh being treated
Point_coord_windows point_traite;

GLint viewport[4] = {0}; // We need an array to hold our view port coordinates
glGetIntegerv(GL_VIEWPORT, viewport); // avec viewport[0]=x et viewport[1]=y et viewport[2]=width et viewport[3]=height

GLdouble modelview[16]; // Where The 16 Doubles Of The Modelview Matrix Are To Be Stored
glGetDoublev(GL_MODELVIEW_MATRIX, modelview); // Retrieve The Modelview Matrix

GLdouble projection[16]; // Where The 16 Doubles Of The Projection Matrix Are To Be Stored
glGetDoublev(GL_PROJECTION_MATRIX, projection); // Retrieve The Projection Matrix

// To hold windows coordonate of the point
Point_coord_windows pos;

for (int i = 0; i < this_file.nb_vertex; i++) {
if (this_file.pt_valid[i]) {
// x, y, z of the point treated
point_traite.X = this_file.pt_ptsGL[3*i];
point_traite.Y = this_file.pt_ptsGL[(3*i)+1];
point_traite.Z = this_file.pt_ptsGL[(3*i)+2];

// find the windows coordonates of the point of the mesh
gluProject(point_traite.X, point_traite.Y, point_traite.Z, modelview, projection, viewport, &winX, &winY, &winZ);

// if we are in the desired rectangle
if ((winX > A.X) && (winX < B.X) && (winY > A.Y) && (winY < C.X)) {
// find if the point is shown or hidden on the screen to take only the good part of the mesh

glReadPixels((GLint) winX, (GLint) winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ); // retrieve winZ
// recompute from the windows coord the point coord at this point on the screen
gluUnProject( winX, winY, winZ, modelview, projection, viewport, &pos.X, &pos.Y, &pos.Z);

// if the points are the same, the point is in the rectangle and not hidden on the screen
if ((fabs(pos.X - point_traite.X)<0.03) && (fabs(pos.Y - point_traite.Y)<0.03) && (fabs(pos.Z - point_traite.Z)<0.03))

nobody know?