PDA

View Full Version : problem with gluUnProject



jirkamelich
12-14-2002, 05:52 AM
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 ?

JustHanging
12-16-2002, 05:15 AM
Hi,

I think this is the problem:

GLdouble winZ;
glReadPixels (Mys.x,y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ);

Your winZ variable is of type GLdouble, but with readpixels you request GL_FLOAT.

-Ilkka