I want to pick some points in my projection. In GL_RENDER, I can draw the scene correctly, but in GL_SELECT, if I comment out glRenderMode(GL_SELECT) , then it will be drew in not the correct place, far away from the correct place, and will become smaller. Codes as follows:
void CProjectView::SelectPoints(CPoint point)
{
GLint viewport[4];
int x,y;
x=point.x;
y=point.y;
glGetIntegerv(GL_VIEWPORT,viewport);
glSelectBuffer(BUFSIZE,selectBuf);
glRenderMode(GL_SELECT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x,(viewport[3]- y),500.0,500.0,viewport);
gluPerspective(10*ZoomFactor,aspect,1,10000.0);
DrawProcessedPoints(GL_SELECT);
glSelectHits=glRenderMode(GL_RENDER);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CProjectView: rawProcessedPoints(GLenum mode)
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glInitNames();
glPushName(0);
glTranslated(SYSVIEWX, SYSVIEWY, SYSVIEWZ);
glRotatef(viewAngle_Z, 0.0, 0.0, 1.0);
glRotatef(viewAngle_Y, 0.0, 1.0, 0.0);
for(int i=0;i<nProDataLength/6;i++)
{ if(mode==GL_SELECT)
glLoadName(i+1);
glPointSize(2.0);
glBegin(GL_POINTS);
glVertex3f((float)(pProcess[i*6]-pProcess[0]),
(float)(pProcess[i*6+1]-pProcess[1]),
(float)(pProcess[i*6+2]-pProcess[2]));
glEnd();
}
glPopMatrix();
}
void CProjectView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
CSize size(cx,cy);
aspect = (cy == 0) ? (double)size.cx : (double)size.cx/(double)size.cy;
glViewport(0,0,cx,cy);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(10*ZoomFactor,aspect,1,10000.0);
gluLookAt(eyePosition.x, eyePosition.y, eyePosition.z, lookPosition.x, lookPosition.y,
lookPosition.z, upAxis.x, upAxis.y, upAxis.z);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDrawBuffer(GL_BACK);
glEnable(GL_DEPTH_TEST);
InvalidateRect(NULL,FALSE);
}