Original Post
Hello, I am currently making a programming that finally has a GUI in ortho mode, but the problem with this is that my selection code does not work. The selection code is shown below: This code does work for objects that are only drawn in projection mode but not in ortho. I have tried searching for a solutions on the internet and in the forums but have either arrived at a dead end or the replies involved utilizing another method such as ray tracing or the back buffer (colors). My scene involves objects drawn in both orthographic and projection views. The objects drawn in projection are simply given an ID that is regarded as being nothing while the objects drawn in ortho are given various IDs to distinguish one from another. Thank you.
int Select(int x, int y)
{
int objectsFound = 0;
int viewportCoords[4] = {0};
unsigned int selectBuffer[128] = {0};
glSelectBuffer(128, selectBuffer);
glGetIntegerv(GL_VIEWPORT, viewportCoords);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glRenderMode(GL_SELECT);
glLoadIdentity();
gluPickMatrix(x, viewportCoords[3] - y, 1, 1, viewportCoords);
gluPerspective(45.0f, (float)g_rRect.right / (float)g_rRect.bottom, 0.1f, 150.0f);
glMatrixMode(GL_MODELVIEW);
DrawScene();
objectsFound = glRenderMode(GL_RENDER);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
if(objectsFound > 0)
{
unsigned int lowestDepth = selectBuffer[1];
int selectedObject = selectBuffer[3];
for(int i = 1; i < objectsFound; i++)
{
if(selectBuffer[(i * 4) + 1] < lowestDepth)
{
lowestDepth = selectBuffer[(i * 4) + 1];
selectedObject = selectBuffer[(i * 4) + 3];
}
}
return selectedObject;
}
return 0;
}