Hi Im new on the world of opengl, jogl
I did some objects. now I want to interact with them. I have this when a click happens
{
context.makeCurrent();
int buff[]=new int[4 * CubeScene.maxSel];
BufferSeleccion= ByteBuffer.allocateDirect(5 * CubeScene.maxSel).order(ByteOrder.nativeOrder()).asIntBuffer();
IntBuffer viewport = IntBuffer.allocate(4);
int[] viewp=new int[4];
GL gl=this.context.getGL();
gl.glSelectBuffer((4 * CubeScene.maxSel ),BufferSeleccion);
gl.glGetIntegerv(GL.GL_VIEWPORT, viewp,IntBuffer.wrap(viewp).arrayOffset());
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
glu.gluPickMatrix(e.x, viewp[3]-e.y, 5, 5, IntBuffer.wrap(viewp));
System.err.println("COORDENADAS: "+e.x+" "+e.y);
//glu.gluPerspective(50.0f, (float)rect.right/(float)rect.bottom, 0.1f, 50.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glPushMatrix();
CubeScene.drawAll(gl,2); // this function is the one who draws
}
here a part of the function who draws
void drawAll(GL gl, int render)
{
if(render==1)
{
int NumSel= gl.glRenderMode(GL.GL_RENDER);
// NumSel really has the valor 1 when the click happens
if(NumSel==-1) NumSel=maxSel;
if(NumSel > 0)
{
int z1;
seleccionado=Scenegrip.BufferSeleccion.get(3);
...
// it is supossed to have 3 elemets in my buffer each one should use 4 spaces. and the third is supposed to have the id of the object I selected
// but it throws in debug mode, java.lang.IndexOutOfBoundsException.
else //2
{
System.err.println(“MODO SELECCION”);
gl.glRenderMode(GL.GL_SELECT);
///////////////// SOLO FUNCA SI TA EN MODO SELECCION////
// Inicializa, limpia, la pila de nombres
// de seleccion.
gl.glInitNames();
// Guarda un primer numero en la pila de
// nombres.
gl.glPushName(0);
GLU glu = new GLU();
id=1;
// here start drawing
gl.glLoadName(id);
float color2[]={1f,0f,0f};
gl.glColor3fv(color,0);
gl.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
glu.gluSphere(MosFet.QUADRIC, RADIUS,2,CubeScene.stacks()*3);
gl.glTranslatef(g/4,0.0f,0.0f);
gl.glTranslatef(g/4,0.0f,0.0f);
gl.glTranslatef(g/4,0.0f,0.0f);
gl.glTranslatef(g/4,0.0f,0.0f);
gl.glTranslatef(g/4,0.0f,0.0f);
gl.glTranslatef(g/4,0.0f,0.0f);
//gl.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
glu.gluSphere(MosFet.QUADRIC, RADIUS,2,CubeScene.stacks());
id++;
…