View Full Version : Selection Problem

08-09-2006, 04:13 AM

If more objects are get overlapped, the hit is not occuring. How to solve this problem?

The code is as follows:


// Hit counter and viewport storeage
GLint hits, viewport[4];

// Setup selection buffer
glSelectBuffer(BUFFER_LENGTH, selectBuff);

// Get the viewport
glGetIntegerv(GL_VIEWPORT, viewport);

// Switch to projection and save the matrix

// Establish new clipping volume to be unit cube around
// mouse cursor point (xPos, yPos) and extending two pixels
// in the vertical and horzontal direction

// Since OpenGL measures
// window coordinates starting at the bottom of the window, and Windows
// measures starting at the top, we need to account for this by
// subtracting the y coordinate from the height of the window. This has
// the effect of reversing the coordinate system (y starts at top)

gluPickMatrix(xPos, viewport[3] - yPos, 2, 2, viewport);

glGetFloatv(GL_PROJECTION_MATRIX, projection);
// Apply perspective matrix
///gluPerspective(30.0f, m_WHRatio, 1.0, 2.0);
glGetFloatv(GL_PROJECTION_MATRIX, projection);


// Draw the scene
if(asc == 1 || asc == 2)

else if(ger == 1 || ger == 2)
GerberDraw ();

// Collect the hits
hits = glRenderMode(GL_RENDER);

if(m_bHighlight == true)

CDocumentationDoc *pDoc = GetDocument();

CFileCollection* FileDetails = (CFileCollection*) pDoc -> aFileCollection_Array.GetAt(FileNo);
CMainCodes* pCodes = (CMainCodes*) FileDetails -> aFile_Details.GetAt(CodeNo);
CLineInformation* pLine = (CLineInformation*) pCodes -> Line_Information.GetAt(LineNo);
pLine -> Highlight = FALSE;


// If a single hit occured, display the info.
if(hits >= 1)

m_bHighlight = true;


if more number of objects are overlapped, the value for the variable "hits" is coming as -1.

08-09-2006, 05:26 AM
Your selection buffer is too small. Read the glSelectBuffer manual:
"If the overflow bit was set when glRenderMode was called, a negative hit record count is returned."
Means if your "hits" variable is negative, only abs(hits) complete records have fit into your selection buffer and you can parse so many, the rest of the buffer is garbage.
Use a dynamic buffer size and increase the size in that case and redo the selection until it succeeds.

08-10-2006, 02:32 AM
Hi Relic,

I followed your advice and corrected the problem. Thank you a lot.

Thanking You,