I need to pick an object on the screen and it seems, it doesn’t work. this is my code
<CODE>
CWindowsGLDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CPaintDC dc(this);
GLuint selectBuffer[BUFFSIZE];
GLint hits;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glSelectBuffer(BUFFSIZE, selectBuffer);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
double size = 0.0, s;
std::vector<Piece *>::iterator it;
for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++) {
s = (*it)->size();
if(s > size) size = s;
}
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(point.x, viewport[3]-point.y, 1.0, 1.0, viewport);
gluPerspective(30.0, 1.0, 0.01 * size, 30.0 * size);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
gluLookAt(0.0, 8.0*size, 6.0*size, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glRotated(angleYVue,1.0, 0.0, 0.0);
glRotated(angleXVue,0.0,1.0,0.0);
for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++)
(*it)->internalDraw(1);
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
hits = glRenderMode(GL_RENDER);
int numPiece = Proces****s(hits, selectBuffer);
for(it = pDoc->graphics.begin(); it != pDoc->graphics.end(); it++)
if( (*it)->getNumeroGL() == numPiece ){
pDoc->pSelected = (*it);
pDoc->pSelected->setSelected();
}
else{
if((*it)->isSelected())
(*it)->setSelected();
}
Invalidate(FALSE);
</CODE>
I’m using glLoadName() and to retrieve the object i’m using
<CODE>
int CWindowsGLView::Proces****s(GLint hits,GLuint buffer[])
{
int i;
int j;
int number;
int name;
GLint z1;
GLint z2;
int zMin = MAX_VALUE;
GLuint *ptr;
ptr = (GLuint *) buffer;
for(i=0;i<hits;i++){ //for each hit
number = *ptr;
ptr++;
z1 = *ptr;//zmin
ptr++;
z2 = *ptr;//zmax
ptr++;
if(z1<zMin){
for(j=0;j<number;j++){ //for each name
zMin = z1;
name = *ptr;
ptr++;
}
}
}
return name;
}
</CODE>
Thanks .