Original Post
I draw a point, then click it, use gluUnProject to convert screen coordinates to world coordinates, this is the code here: void display() { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); glTranslatef(0.0f, 0.0f, -2.0f); glColor3f( 1.0f, 1.0f, 1.0f ); glPointSize( 3.0f ); // draw a point glBegin( GL_POINTS ); glVertex3f( 0.0f, 0.0f, 0.0f ); glEnd(); // Click the point, get its world coordinates if ( MOUSE_BUTTON == GLUT_LEFT_BUTTON ) { double posX,posY,posZ; screen2world( MOUSE_POS_X, MOUSE_POS_Y, &posX, &posY, &posZ ); MOUSE_BUTTON = -1; } } void screen2world( int x, int y, double * posX, double * posY, double * posZ ) { GLint viewport[ 4 ]; GLdouble projection[ 16 ]; GLdouble modelview[ 16 ]; GLfloat winX,winY,winZ; glGetIntegerv( GL_VIEWPORT, viewport ); glGetDoublev( GL_PROJECTION_MATRIX, projection ); glGetDoublev( GL_MODELVIEW_MATRIX, modelview ); winX = (GLfloat)x; winY = (GLfloat)( viewport[3] - y ); glReadBuffer(GL_BACK); glReadPixels( winX, winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ); gluUnProject( winX, winY, winZ, modelview, projection, viewport, posX, posY, posZ ); printf( "screen = %f,%f,%f\n", winX, winY, winZ ); printf( "world = %f,%f,%f\n", *posX, *posY, *posZ ); } When i click the point, the posZ is alway zero, I think it will be -2.0, before i draw it, it was translated -2.0, why the result is zero? Thanks!