Hello Guest

Screen Picking help *CHANGED*

  • 0 Replies
Screen Picking help *CHANGED*
« on: February 19, 2007, 20:51:41 »
I apologize if this problem was already answered, or is incredibly simple.  I'm new to lwjgl, but programmed opengl in C++ for a little while now.  I never did screen picking with c++ but I'm trying for the first time with java.  I'm using SWT GLCanvas for drawing, and have the rendering in a seperate thread.  The code supposedly executes, and I get the correct number of hits, but the values in the selection buffer are WAY off.  When I use 0 and -1 for the glLoadName() it works, I get those values back correctly, but everything else I get huge numbers, both positive and negative, and I have no clue why.  Any and all help would be apprecaited!

Code: [Select]
protected Point pickLocation(int x, int y) {
y = this.getSize().y - y;
int[] view = new int[4];
int buffer[] = new int[256];
IntBuffer selBuf = ByteBuffer.allocateDirect(64).order(ByteOrder.nativeOrder()).asIntBuffer();
    GL11.glGetInteger(GL11.GL_VIEWPORT, selBuf);
        selBuf = ByteBuffer.allocateDirect(1024).asIntBuffer();

        //Set render to select mode for picking

        GL11.glInitNames();                                              // Initializes The Name Stack
        GL11.glMatrixMode(GL11.GL_PROJECTION);                       // Selects The Projection Matrix
        GL11.glPushMatrix();      // Push The Projection Matrix
        GLU.gluPickMatrix(x, y, rng, rng, view);
        GLU.gluPerspective(45.0f, (float) (view[2] - view[0]) / (float) (view[3] - view[1]), 0.1f, 250.0f);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);                                 // Select The Modelview Matrix
        GL11.glMatrixMode(GL11.GL_PROJECTION);                                // Select The Projection Matrix
        GL11.glPopMatrix();                                              // Pop The Projection Matrix
        //return to normal rendering
        int hits = GL11.glRenderMode(GL11.GL_RENDER);
        for (int z = 0; z < hits * 4; z++) System.out.println(buffer[z]);
//determine which were selected
ArrayList<MLocation> temp = new ArrayList<MLocation>(hits);
for (int z = 0; z < hits; z++) {
int cur = buffer[z * 4 + 3];
//int cur = selBuf.get(z * 4 + 3);
temp.add(new MLocation((cur - (cur % 100)) / 100,cur % 100));
        //System.out.println(x  + ", " + y + " :: " + hits);
return null;

The x, and y passed in are the mouse location on the screen, drawBoard is a method that draws and names the polygons I'm trying to pick.  I pieced much of the code from other forums and the nehe tutorial, but I can't seem to get it to work.  Thanks for the help!
« Last Edit: February 27, 2007, 07:18:08 by white_dot1 »