OpenGl - selection

Hi guys trying to get picking to work basically just rendering a pyramid to test the picking and i’m getting hits = 0 each time.

Any help would be greatly appreciated as i’ve never tried to do picking before and have just been reading the theroy so i could have something completely wrong.

Thanks!


public int pickOBJ(double eyeX, double eyeY, double eyeZ, double cenX, double cenY, double cenZ, int x, int y)
        {
            Gl.glRenderMode(Gl.GL_SELECT); 
            Gl.glInitNames();  
            Gl.glPushName(0);
            int selectedId = -1;
            int[] selectBuffer = new int[512];
            int[] viewport = new int[4];
            Gl.glGetIntegerv(Gl.GL_VIEWPORT, viewport);
            Gl.glSelectBuffer(512, selectBuffer);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glPushMatrix();
            Gl.glLoadIdentity();

            Glu.gluPickMatrix(x, y, 0.01f, 0.01f, viewport);
            Glu.gluLookAt(eyeX, eyeY, eyeZ, cenX, cenY, cenZ, 0, 1, 0);	
            Gl.glTranslatef(0, 0, 0);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            DrawPri(0, 0, 0);
            Gl.glFlush();
            int hits = Gl.glRenderMode(Gl.GL_RENDER);
            uint closest = uint.MaxValue;

            for (int i = 0; i < hits; i++)
            {
                uint distance = (uint)selectBuffer[i * 4 + 1];

                if (closest >= distance)
                {
                    closest = distance;
                    selectedId = (int)selectBuffer[i * 4 + 3];
                }
            }
            return selectedId;
        }

I figured it out it had to do with how i was setting it up at the start.