i have a problem with gluUnProject.
I have this source code :
declarations :
GLdouble winZ;
GLint y;
GLint viewport[4];
GLdouble projection[16];
GLdouble modelview[16];
POINT Mys;
Paint :
.
.
.
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
y = viewport[3] - Mys.y;
glReadPixels (Mys.x,y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);
//------------------------
MouseClick :
wglMakeCurrent(Canvas->Handle,hRC);
GLdouble x;
GLdouble y;
GLdouble z;
gluUnProject ((GLdouble) Mys.x, (GLdouble) Mys.y, (GLdouble) winZ,modelview, projection, viewport, &x, &y, &z);
ShowMessage(z);
wglMakeCurrent(NULL,hRC);
and i get incorrect z,y,x everytime.
even i move the mouse on some quad ( z coordinate is 0) it gives me a bit defferent z coordinates.
Has somebody working example of using gluUnProject ?