@theagentd
i used the following instead which seemed to compile for me:
private DoubleBuffer getMousePosition(int mouseX, int mouseY, GL GL11) {
IntBuffer viewport = BufferUtil.newIntBuffer(16);
DoubleBuffer modelview = BufferUtil.newDoubleBuffer(16);
DoubleBuffer projection = BufferUtil.newDoubleBuffer(16);
DoubleBuffer winZ = BufferUtil.newDoubleBuffer(1);
DoubleBuffer position = BufferUtil.newDoubleBuffer(3);
GL11.glGetDoublev(GL11.GL_MODELVIEW_MATRIX, modelview);
GL11.glGetDoublev(GL11.GL_PROJECTION_MATRIX, projection);
GL11.glGetIntegerv(GL11.GL_VIEWPORT, viewport);
GL11.glReadPixels(mouseX, mouseY, 1, 1, GL11.GL_DEPTH_COMPONENT, GL11.GL_DOUBLE, winZ);
if (winZ.get(0) == 1) {
return null;
}
glu.gluUnProject((double)mouseX, (double)mouseY, (double)winZ.get(0), modelview, projection, viewport, position);
System.out.println(position.get(0)+" "+position.get(1)+" "+position.get(2)+" "+winZ.get(0));
return position;
}
Thanks for your reply man but it didn’t give me the correct z positions. I had a simple sphere, and used a mouse click coordinates to run the getMousePosition method, however it only ever returned winZ as 0 (converting to a projection.get(2) of 0.5 for everything). Whereas i want to know the different z-values for different parts of the sphere.
@gouessej
Ive been trying to use openGL picking but have been getting depth-values of like 1578192816 and even after reading about glSelectBuffer I still don’t know how to turn this into a z-coordinate. I know to divide by 2^31 but even then im not sure what it means.