Why does gluProject() Fail?

I’m trying to use gluProject for the first time and it always returns an error. Any idea why? Essentially the code is:

glGetDoublev (GL_MODELVIEW_MATRIX, model);
glGetDoublev (GL_PROJECTION_MATRIX, proj);
glGetIntegerv (GL_VIEWPORT, view);
retVal = gluProject(0, 0, 0, model, proj, view, winX1, winY1, winZ1);

retVal comes back GL_FALSE.

I’ve checked in the debugger that model, proj, and view come back correctly from
the glGet calls. The object point (0,0,0) I know is on the screen. Any ideas?

Thanks, Lorax

gluProject transforms the point with the projections, and if
the z component is zero, it returns GL_FALSE:

From the Mesa source code:

// normalize the point - check for divide by zero
if (in[3] == 0.0)
return GL_FALSE;

Your projections could be bad. This is the only line in
the entire function that gluProject returns false.

Thanks for your response, Syslock. I tried it out. You’re right, If the objZ parameter is non-zero, gluProject does not fail, as you indicated. But I still don’t understand.

I guess I’ve misunderstood what the objX, objY, objZ parameters to gluProject are. I thought that they were the coordinates in opengl space of point of interest, which in this case is the origin of my data display. (It is also the “LookAt” point for gluLookAt in my code.) Should the parameters be something different? Or, does the objZ parameter need to be scaled to [0,1]? Could it be that all points on the x-y plane invalid input to gluProject()? This seems curiously undocumented. I have both the red and blue books…

Best, Lorax

[This message has been edited by Lorax (edited 12-04-2001).]

Oops, not the z coordinate. It looks like the w component:

in[0] = objx;
in[1] = objy;
in[2] = objz;
in[3] = 1.0;

You should be able to transform any 3D point (objx, objy, objz).

Maybe you should inspect your projections a little more closely. Dump their values out
and see what they are.

Get the source code here:

Hi Syslock,
Well, I knew you were right about the projections, but I had no idea what the projections should look like. After a day of staring at the debugger, and at Appendex F of the red book and reading Steve Baker’s “Matrices can be your Friends”, I finally figured it out. Thanks for your help.

Originally posted by Syslock:
Maybe you should inspect your projections a little more closely. Dump their values out
and see what they are.