Hello Guest

Problem Depth values with GLSelectBuffer and gluPickMatrix

  • 1 Replies
  • 6145 Views
Good Morning everyone!

I tried to do some picking using the method GLSelect and gluPickMatrix.
This technique worked on a C/GLUT code but with LWJGL I had some problems.
I need to correct the depth value with this:
Code: [Select]
int depthMin = (buffer[k++] >> 8)  & 0x00FFFFFF;Where buffer is the selected buffer.
This is my picking code (I select the element with the minimum depth):
Code: [Select]
int[] viewport = new int[4];
int buffer[] = new int[loader.getNbCells()*4];

GL11.glGetInteger(GL11.GL_VIEWPORT, viewportBuffer);
viewportBuffer.get(viewport);
viewportBuffer.clear();
GL11.glSelectBuffer(selectBuffer);
GL11.glRenderMode(GL11.GL_SELECT);

GL11.glInitNames();
GL11.glPushName(0);

GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GLU.gluPickMatrix((float) mouseListener.prevMouseX, (float)viewport[3] - mouseListener.prevMouseY, 1.0f, 1.0f,IntBuffer.wrap(viewport));
setScene(screenRatio, loader.getDataSetRatio());
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glCallList(modelDisplayList);

GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);

int hits = GL11.glRenderMode(GL11.GL_RENDER);
selectBuffer.get(buffer);

if(hits > 0) {
    int k = 0;
    int depth = Integer.MAX_VALUE;
    int cellId = -1;
    for (int i = 0; i < hits; i++) {
       int stackSize = buffer[k++];

//To correct the depthMin value;
int depthMin = (buffer[k++] >> 8)  & 0x00FFFFFF;
if (depthMin < depth) {
    depth = depthMin;
    k++;
    cellId = buffer[k++];
    k += stackSize - 1;
} else {
    k += 1 + stackSize;
}
   }
    updateSelectColor(cellId);
}

If I don't correct the depth Value, I have sometimes an another element selected.

I am on Ubuntu 10.04 32Bits, LWJGL 2.5 and Java(Sun) 1.6 with an Nvidia Quadro FX1800 and Xeon W3520

If it can helps to avoid some headaches  ;)

Regards

Re: Problem Depth values with GLSelectBuffer and gluPickMatrix
« Reply #1 on: July 22, 2010, 13:39:30 »
I know this may not directly help. But generally in opengl docs it is recommended not to use GL_SELECT anymore. Its recommended to do it all in user space with glUnproject (IIRC).
If you want a plot read a book and leave Hollywood out of it.