This is the first time I’m using this function so can anyone here help me.
I’m creating a program that can click on the geometry on it. My first step to do this is to know how to convert the Windows’ coordinate to OpenGL.
Here’s the code I found somewhere on the net. I’m using java by the way but most of the code stay the same so no problem with it.
My question is why does my wcoord didn’t get any coordinates?
public boolean isClicked(GL gl, GLU glu, int x, int y)
{
int[] viewport = new int[4];
double[] modelview = new double[16];
double[] projection = new double[16];
int winX, winY, winZ;
double[] wcoord = new double[4];
gl.glGetDoublev( gl.GL_MODELVIEW_MATRIX, modelview, 0 );
gl.glGetDoublev( gl.GL_PROJECTION_MATRIX, projection, 0 );
gl.glGetIntegerv( gl.GL_VIEWPORT, viewport, 0 );
winY = viewport[3] - y - 1;
//gl.glReadPixels( x, winY, 1, 1, gl.GL_DEPTH_COMPONENT, gl.GL_INT, winZ );
glu.gluUnProject( x, winY, 0.0, modelview, 0, projection, 0, viewport, 0, wcoord, 0);
System.out.println("X: "+wcoord[0]+" Y: "+wcoord[1]+" Z: "+wcoord[2]+" W: "+wcoord[3]);
return false;
}