Advertisement

Selection in Ortho Mode

Started by September 24, 2002 05:15 PM
-1 comments, last by SoD 22 years, 5 months ago
Hi, i''ve to implement in my game a selection of 3D Objects on the screen (perspective mode) and in the same time selection of the objects of the GUI like information windows, etc(ortho mode). enabling the selection buffer both for 3d objects and windows with a single call works very bad, it returns always something selected or always nothing depending where glLoadName is put. So i''ve done a function for selection checking of 3d objects and all works well, but i with ortho mode there''s always no selection, i don''t understand what can be. the RetrieveUI_ID is this: int CApp::RetrieveUI_ID(int x, int y) { int objectsFound = 0; int viewportCoords[4] = {0}; unsigned int selectBuffer[32] = {0}; glSelectBuffer(32, selectBuffer); glGetIntegerv(GL_VIEWPORT, viewportCoords); glMatrixMode(GL_PROJECTION); glPushMatrix(); glRenderMode(GL_SELECT); glLoadIdentity(); // set the selection area around the mouse cursor gluPickMatrix(x, viewportCoords[3] - y, 2, 2, viewportCoords); glOrtho( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0,1/*1 , 10*/ ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // call the window draw function m_window.Draw(); PerspectiveMode(); objectsFound = glRenderMode(GL_RENDER); 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; } The rendering function is : void CUIWin::Draw() { glColor3f(1.0f, 1.0f, 1.0f); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_ONE,GL_ONE); glEnable(GL_BLEND); glInitNames(); glPushName(0); glLoadName(UI_WINDOW); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_IDcorner_texture); glBegin(GL_QUADS); // TOP LEFT ANGLE glTexCoord2f(0.0f, 1.0f); glVertex2i(m_x,m_y); glTexCoord2f(0.0f, 0.5f); glVertex2i(m_x,m_y+20); glTexCoord2f(0.5f, 0.5f); glVertex2i(m_x+20,m_y+20); glTexCoord2f(0.5f, 1.0f); glVertex2i(m_x+20,m_y); .... glEnd(); // TOP RIGHT ANGLE .. .. . . ... //... } Is the Retrieve function wrong? Thanks for any suggetion
Here we go!

This topic is closed to new replies.

Advertisement