Hello,
i've got a problem concerning selection with JOGL (not Java3D).
I created a simple programm in which the user should be able to select object but it doesn't work and since opengl is a bit harder to debug, i ask you:
my code:
Drawing Function:
public void DrawFrameNamed(BDSFrame f)
{
gl.glTranslatef(0.0f,0.0f,-10.0f);
for(int i=0;i<f.objs.size();i++)
{
BDSObject cur = f.objs.get(i);
gl.glLoadName(i+1);
DrawReadyObject(cur);
}
}
PICKING:
public void SimpleClickSelection(int x,int y, BDSFrame f)
{
int bufsize = 32;
IntBuffer selbuf = BufferUtil.newIntBuffer(bufsize);
int[] viewport = new int[4];
gl.glGetIntegerv(gl.GL_VIEWPORT,viewport,0);
gl.glSelectBuffer(bufsize,selbuf);
gl.glRenderMode(gl.GL_SELECT);
gl.glMatrixMode(gl.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
glu.gluPickMatrix(x,viewport[3]-y, 2.0d, 2.0d, viewport, 0);
glu.gluPerspective(45, viewport[3]/viewport[2], 0.1, 1000);
gl.glInitNames();
gl.glMatrixMode(gl.GL_MODELVIEW_MATRIX);
DrawFrameNamed(f);
int hits;
gl.glMatrixMode(gl.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(gl.GL_MODELVIEW);
gl.glFlush();
hits = gl.glRenderMode(gl.GL_RENDER);
System.out.println("HITS:"+hits);
}
it's always HITS=0 ? and i really don't know where the mistake is.
thanks ;)