Original Post
Somehow when there are two triangles, one front and one behind, the program will always pick the one in the back. Here's the code, is this enough?Or I need to modify, how? void pick(GLfloat xpos,GLfloat ypos) { xpos,ypos; GLint viewport[4]; GLdouble mvmatrix[16],projmatrix[16]; GLint realy; GLdouble wx,wy,wz; glGetIntegerv(GL_VIEWPORT,viewport); glGetDoublev(GL_MODELVIEW_MATRIX,mvmatrix); glGetDoublev(GL_PROJECTION_MATRIX,projmatrix); realy = viewport[3]-(GLint)ypos -1; gluUnProject((GLdouble)xpos,(GLdouble)realy,0.0,mvmatrix,projmatrix,viewport,&wx,&wy,&wz); g_nearxyz[0] = (GLfloat)wx; g_nearxyz[1] = (GLfloat)wy; g_nearxyz[2] = (GLfloat)wz;//// gluUnProject((GLdouble)xpos,(GLdouble)realy,1.0,mvmatrix,projmatrix,viewport,&wx,&wy,&wz); g_farxyz[0] = (GLfloat)wx; g_farxyz[1] = (GLfloat)wy; g_farxyz[2] = (GLfloat)wz;//// }