Hi all. I’ve been going at this all nite. I thought the selection stuff would be straight forward. not so much…here is the code I basically copied from this tutorial:
http://www.lighthouse3d.com/opengl/picking/index.php?openglway2
void PointMesh::Selection()const
{
GLint viewport[4];
GLuint selectionBuffer[512];
int hits;
glSelectBuffer(512,selectionBuffer);
glRenderMode(GL_SELECT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glGetIntegerv(GL_VIEWPORT,viewport);
gluPickMatrix(viewport[2]*_mouse[0],viewport[3]*_mouse[1],
150.0,150.0,viewport);
gluPerspective(45,(GLfloat) (viewport[2]-viewport[0])/(GLfloat) (viewport[3]-viewport[1]),0.1,1000);
glMatrixMode(GL_MODELVIEW);
glInitNames();
_drawUVPoints();
// restoring the original projection matrix
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glFlush();
// returning to normal rendering mode
hits = glRenderMode(GL_RENDER);
GLenum glerr = glGetError();
while(glerr != GL_NO_ERROR) {
std::cout<<"glGetError:"<<gluErrorString(glerr)<<std::endl;
glerr = glGetError();
}
if (hits > 0)
{
std::cout<<"Hit a ctrl point"<<std::endl;
/*int choose = selectionBuffer[3];
int depth = selectionBuffer[1];
for (int loop = 1; loop < hits; loop++)
{
// If This Object Is Closer To Us Than The One We Have Selected
if (selectionBuffer[loop*4+1] < GLuint(depth))
{
choose = selectionBuffer[loop*4+3];
depth = selectionBuffer[loop*4+1];
}
}*/
}
}
and here is the referenced _drawUVPoints() function:
void PointMesh::_drawUVPoints()const
{
//u iso-curves
if(!_selection)
{
glEnable(GL_POINT_SMOOTH);
}
glPointSize(5.0);
for(unsigned int v = 0; v < _numVControlPoints; v++)
{
for(unsigned int u = 0; u < _numUControlPoints; u++)
{
glLoadName(v*_numUControlPoints + u);
glBegin(GL_POINTS);
glVertex3f(_controlPoints->at(v*_numUControlPoints + u).X(),
_controlPoints->at(v*_numUControlPoints + u).Y(),
_controlPoints->at(v*_numUControlPoints + u).Z());
glEnd();
}
}
if(!_selection)
{
glDisable(GL_POINT_SMOOTH);
}
}
When I try selecting with the mouse, I get no hits and I also see a duplicate (un-correctly positioned) set of points. Clicking the mouse in different areas of the window moves the duplicate set of points around in the window… Not sure what’s going on…does anyone see anything blatently wrong with my code?
Thanks in advance
biv
Oh, I have the mouse coords already “transformed” to gl window coords by the time I reach this function but my window is not full screen. I also have an obscene size for my selection window but I was trying to debug.