gluUnProject returning 0s?

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;
	}

why did u comment this line :
//gl.glReadPixels( x, winY, 1, 1, gl.GL_DEPTH_COMPONENT, gl.GL_INT, winZ );

After picking a pixel with the mouse, u have to read the depth buffer on that pixel location than supply x,y and z to ur gluUnproject :
GLfloat winZ;
winY = viewport[3] - y;
glReadPixels( x, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ );
gluUnProject( x, winY, winZ, modelview, projection, viewport,…
dont forget to redefine winY as a double
this will be helpful
http://nehe.gamedev.net/data/articles/article.asp?article=13