PDA

View Full Version : gluProject issues


boombatower
06-13-2007, 03:18 PM
DoubleBuffer model = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, model);

DoubleBuffer proj = DoubleBuffer.allocate(16);
gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, proj);

IntBuffer view = IntBuffer.allocate(4);
gl.glGetIntegerv(GL.GL_VIEWPORT, view);

DoubleBuffer winPos = DoubleBuffer.allocate(3);
glu.gluProject(x, y, z, model, proj, view, winPos);


Everywhere else I see this it works, but for me it doesn't. I get something that is [(same as object's x), 1024, 3]

Example matrices that OpenGL is returning:

MODELVIEW_MATRIX:
[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]

PROJECTION_MATRIX
[0.0015625000232830644, 0.0, 0.0, 0.0, 0.0, -0.001953125, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 1.0, -0.0, 1.0]

VIEWPORT
[0, 0, 1280, 1024]


I am using Java and JOGL. Any suggestions on how to debug this?

Reedbeta
06-13-2007, 09:31 PM
Make sure you set the matrix mode (glMatrixMode), and load the identity (glLoadIdentity) before calling gluProject.

boombatower
06-16-2007, 02:36 PM
The problem was that I was attempting to get the matrices from OpenGL after I had set it up to render 2d. Thus the matrices were not what they are for 3d. I already have a camera class that contained the matrices and after using them it worked.

Thanks for the response.