this is my code... plz.. what am i doing wrong??..
Code:
protected override void OnClick(EventArgs e)
{
int x = MousePosition.X;
int y = MousePosition.Y;
int[] viewport = new int[4];
double[] modelview = new double[16];
double[] projection = new double[16];
float winX, winY, winZ;
unsafe
{
double posX, posY, posZ;
GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelview);
GL.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection);
GL.glGetIntegerv(GL.GL_VIEWPORT, viewport);
winX = (float)x;
winY = (float)viewport[3] - (float)y;
GL.glReadPixels((int)winX, (int)winY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, &winZ);
GL.gluUnProject(winX, winY, winZ, modelview, projection, viewport, out posX, out posY, out posZ);
MessageBox.Show(posX.ToString() + "," + posY.ToString() + "," + posZ.ToString());
}
}
its a simple function on the click event.. and it prints the 3d coords.
Edit.. Btw, im using OpenGL with C#