OpenGL拾取的问题!(附源码)
在WM_LBUTTONDOWN中响应
void COpenGL::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
GLuint selectBuf[BUFSIZE];
GLint hits;
GLint viewport[4];
int x, y,gi,elenum,i;
x = point.x;
y = point.y;
glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (BUFSIZE, selectBuf);
(void) glRenderMode (GL_SELECT);
glInitNames();
glPushName(-1);
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glPushMatrix();//
glLoadIdentity();
gluPickMatrix((GLdouble) x, (GLdouble) (viewport[3] - y), 25.0, 25.0, viewport); //设置选择区域
gluPerspective(80.0f,1.0,1.0f,2000.3f);
//-----------------------绘制选择的物体---------------------
glPushMatrix();
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,-ShipDimen.length/160.0*130.0f+Vp.tranz);//Vp.tranx
glMultMatrixf(Transform.M);
glRotatef(Vp.yrot,0.0f,1.0f,0.0f);
glRotatef(-90.0f+Vp.xrot,1.0f,0.0f,0.0f);
glPushMatrix();
glTranslatef(-ShipDimen.length/2.0f+Vp.tranx,0.0f,-ShipDimen.depth/2.0f); //设置旋转中心点
gi=Group.SlctGp;
elenum=Group.GpQd[gi][0][0][0];
for(i=1;i<=elenum;i++)
{
glLoadName (i);//压入名称列表
glBegin(GL_QUADS);
glVertex3f(Group.GpQd[gi][i][0][0],Group.GpQd[gi][i][0][1],Group.GpQd[gi][i][0][2]);
glVertex3f(Group.GpQd[gi][i][1][0],Group.GpQd[gi][i][1][1],Group.GpQd[gi][i][1][2]);
glVertex3f(Group.GpQd[gi][i][2][0],Group.GpQd[gi][i][2][1],Group.GpQd[gi][i][2][2]);
glVertex3f(Group.GpQd[gi][i][3][0],Group.GpQd[gi][i][3][1],Group.GpQd[gi][i][3][2]);
glEnd();
}
glPopMatrix();
glPopMatrix();
//-----------------------绘制选择的物体---------------------
glPopMatrix ();
glFlush ();
hits = glRenderMode (GL_RENDER);
processHits (hits, selectBuf);
CWnd::OnLButtonDown(nFlags, point);
}
hits = glRenderMode (GL_RENDER);
hits返回值总是为0,不知道那里错了
请各位大侠帮帮忙
看一下程序那里的问题