gluUnProject returns wrong values

Hi,

I’m using gluUnProject to convert Screen coordinates to OpenGL. For most of the time it works fine but sometimes the function returns wrong value.

For example I move mouse around the screen and Z value are Ok until the cross -120. Then the Z value is suddenly -630. The X value is OK.

I would be grateful for any tip what can cause this problem.

Regards.

Could this be an issue of Z precision in the depth buffer. (I’m honestly not sure, but I feel like there might be something like that going on…)