   gluUnproject
  Hi @ all,i have a strange problem with gluUnproject an couldn´t find anything in the forums.Im doing raypicking, which works perfectly in my testapp. However, if i execute the same code in my other app it doesnt work. the problem is that the intersection point has always an offset along thy cams local z-axis (viewing direction). I think its because the app im developing uses both, orthographic and persepective view, rendering to 2 different windows. I draw things in 2D in one window and visualize it in 3D in another window.To create the 3D View i have 2 Device contexts, one associated to the 2D window, and the other to the 3D window, but only one GLContext.Every time i switch from 2D to 3D, i swicth the context with wglMakeCurrent(newHWContext, GLContext)rendering the 3d in a seperate window.Could it be that the problem is the swicth and my Projection and Modelview matrices are therefor not correct?public void switchRendermode(Rendermode newMode)   {  //swicth to 3D-Mode  if (newMode == Rendermode.RM_3D)  { Wgl.wglMakeCurrent(IntPtr.Zero, IntPtr.Zero); Wgl.wglMakeCurrent(mGDIContext3D, mGLRenderContext); Gl.glViewport(0, 0, mRenderWindow3D.Width, mRenderWindow3D.Height); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Glu.gluPerspective(45, (double)mRenderWindow3D.Width / (double)mRenderWindow3D.Height, 0.1, 20000.0); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity();}   } mGDIContext3D is the context hich is associated to my seperate 3D renderwindow.As you can see im setting the viewport and the persepective projection.Just tell me if you need more code. But maybe it is a general problem with this kind of app im writing.Hope someone can help me :DThanks in advance and greetz;P.S. My testapp (the app which produces perfect results) uses just one Window rendering only in 3D.   
  The code where you call gluUnProject would certainly be of service [smile]   ;  Ok youre right. Just thought because it is the same code in both apps, it can´t be the source.public Ray rayFromMousePos(int mouseX, int mouseY)   {  double[] proj = new double[16]; //Holds the projection matrix  double[] model = new double[16]; //Holds the modelview matrix  int[] vp = new int[4]; //Holds viewport data  //Variables holding the transformed points at the near and far   //clipping plane  double sX;  double sY;  double sZ;  //Get Data  Gl.glGetDoublev(Gl.GL_PROJECTION_MATRIX, proj);  Gl.glGetDoublev(Gl.GL_MODELVIEW_MATRIX, model);  Gl.glGetIntegerv(Gl.GL_VIEWPORT, vp);  //Get Transformed screencoord at the near plane  Glu.gluUnProject(mouseX, vp[3] - mouseY, 0, (double[])model, (double[])proj, vp, out sX, out sY, out sZ);   Vector3 start = new Vector3((float)sX, (float)sY, (float)sZ);  //Get Transformed screencoord at the far plane  Glu.gluUnProject(mouseX, vp[3] - mouseY, 1, (double[])model, (double[])proj, vp, out sX, out sY, out sZ);   Vector3 end = new Vector3((float)sX, (float)sY, (float)sZ);  //Calculate the direction of the ray  Vector3 dir = end- start;  return new Ray(dir, start);   }