selection + multiple viewport

Hi all,

I’ve encountered a problem that stuck me for a couple of days already.

I used to have 4-view on my screen, set by glViewport separately on drawing.

But I couldn’t be able to pick object correctly following Redbook’s example.

I always can’t get the viewport right on a mouse click event by glGetIntegerv(GL_VIEWPORT, viewport), even i’ve determined which viewport the mouse cursor belongs to

I think this is due to i modify the viewport 4 times on drawing the 4 view.

What makes it even worse is, if I set the viewport in gluPickMatrix after determining the cursor position instead of using glGetIntegerv(…), I even can’t make any selection hit.

Does any one can help on it?

Thanks sooooooooo much.

further information, my codings are somewhat like this, with this code, i always get 0 selection hits -___-:

int CModelSystemView::PickObject() {

GLuint selectBuf[512];
GLint hits, viewport[4];

// set the viewport relative to the whole display window
glSelectBuffer(512, selectBuf);

glRenderMode(GL_SELECT);
glInitNames();
glPushName(-1);

// redraw the scene for picking

if (curr_viewport == XY_VIEW) { // cursor position belongs to the X-Y axis viewport
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();

gluPickMatrix(m_startPosX, viewport[3] - m_startPosY, 1, 1, viewport);

glOrtho2D( -w, w, -w, w);

glMatrixMode( GL_MODELVIEW);
glLoadIdentity();
	
glPushMatrix();
   drawSomething();
glPopMatrix();

glFlush();
glPopMatrix();

}

else if (curr_viewport == XZ_VIEW) {
// …

}

hits = glRenderMode(GL_RENDER);
proces****s(…);

return hits;

}