Hi guys.
I try to get the code to work, but i don´t see why it doesn´t work. The function will be called by “OnMouseClick” in MFC and receive X and Y Pos of the Mouse which are ok.
Please don´t send me any tutorial links. I got enough and thought that i understand them
void COpenGL::select_object(int xPos, int yPos)
{
GLuint buffer[BUFFER_LENGTH];
GLint hits, viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport); // Get the viewport
glSelectBuffer(BUFFER_LENGTH,buffer); // buffer muss für jedes Object das ausgewählt wird 4 byte bereitstellen
(void) glRenderMode(GL_SELECT); // Change render mode
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION); // Switch to projection and save the matrix
glPushMatrix();
glLoadIdentity();
gluPickMatrix( (GLdouble) xPos,(GLdouble) (viewport[3] - yPos),5,5,viewport);
// TEST ***************************
glLoadName (0);
glPushName (1);
glColor3f (0.0, 1.0, 1.0);
glRectf ( 0.0, 0.0, 1.0, 1.0);
glPopName ();
glPushName (2);
glColor3f (1.0, 0.0, 1.0);
glRectf ( -1.0, -1.0, 0.0, 0.0);
glPopName ();
// TEST END ***********************
glMatrixMode(GL_PROJECTION); // Restore the projection matrix
glPopMatrix();
glFlush();
hits = glRenderMode(GL_RENDER);
if (hits > 0) TRACE("HIT FOUND
");
}
Thx in advance
daSickboy