I have been unable to get Selection to return a non-zero number of hits. Here is the way the code is laid out.
- I draw the scene as normal (no selection code)
- I have a mouse listener that listens for a mouseClicked
- On receiving the mouse click, I set a flag (actually the point clicked) and call repaint on my GLJPanel.
- In the GLPanel’s display() method I check the selection flag. If it is set I call glSelectBuffer, glRenderMode, etc.
- At the end of the display() method, I call glRenderMode( GL.GL_RENDER ) and print out the returned numHits. This is always 0.
Here is the code snippet within the display() method:
// Draw DSO's
IntBuffer selectBuffer = null;
try
{
if ( clickedPt != null )
{
selectBuffer = BufferUtil.newIntBuffer( objects.size( ) * 8 );
gl.glRenderMode( GL.GL_SELECT );
gl.glSelectBuffer( 0, selectBuffer );
gl.glInitNames( );
gl.glPushName( 0 );
}
// This method calls gl.glLoadName( i ); for each object drawn
drawDSOs( gl );
}
finally
{
if ( selectBuffer != null )
{
int numHits = gl.glRenderMode( GL.GL_RENDER );
processHits( numHits, selectBuffer );
}
clickedPt = null;
}
My numHits is always zero. Can anyone see anything wrong with this code? Am I going about this in the right way?