Hello I want to conver screen coordinate to OPENGL coordinate. but glReadPixels function doesnt work .
I'm using c#. For two days I couldnt solve this problem. the code is below:
void ikt_viewPort3d_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
unsafe
{
float winX, winY, winZ;
isClicked= true;
Int32[] viewPort = new Int32[4];
GL.glGetIntegerv(GL.GL_VIEWPORT, viewPort);
double[] modelView = new double[16];
GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelView);
double[] projection = new double[16];
GL.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection);
winX = eXPre = (float)e.X;
winY = eYPre = (float)e.Y;
winY = viewPort[3] - winY;
byte[] byt = new byte[4];
uint[] pix=new uint[1];
GL.glReadPixels((int)winX, (int)winY, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT, byt);
winZ = System.BitConverter.ToSingle(byt, 0);
double objX, objY, objZ;
GL.gluUnProject(winX, winY, winZ, modelView, projection, viewPort, out objX, out objY, out objZ);
MessageBox.Show("x : " + winX.ToString() + "y: " + winY.ToString() + "z: " + winZ.ToString());
MessageBox.Show("x : " + objX.ToString() + "y: " + objY.ToString() + "z: " + objZ.ToString());
}
}
I'm waiting your answer . Thanks....The solution is very valuable for me.