0

I Am trying to implement picking in a NSOpenGLView , but not works, this is the code.

I render only the objects that I need pick with no lights and I render the scene as same in normal render.

- (void)drawSeleccion
{
    NSSize size = [self bounds].size;

    GLuint selectBuf[16 * 4] = {0};
    GLint hits;

    glClearColor (0.0, 0.0, 0.0, 0.0);
    glColor4f(1.0, 1.0, 1.0, 1.0);

    glSelectBuffer (16 * 4, selectBuf);
    glRenderMode(GL_SELECT);

    /// *** Start ***
    glInitNames();
    glPushName(0);

    // view port.
    glViewport(0, 0, size.width, size.height);

    // projection matrix.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    float dist = 534;
    aspectRatio = size.width / size.height;
    nearDist = MAX(10, dist - 360.0);
    farDist = dist + 360.0;

    GLKMatrix4 m4 = GLKMatrix4MakePerspective(zoom, aspectRatio, nearDist, farDist);
    glMultMatrixf(m4.m);

    // Model view.
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // I look at.
    GLKMatrix4 glm = GLKMatrix4MakeLookAt(0, dist, 0, 0, 0, 0, 0, 0, 1);
    glMultMatrixf(glm.m);

    // rotate viewPort.
    glRotated(rotate_x, 1, 0, 0);
    glRotated(rotate_z, 0, 0, 1);

    glTranslated(translate_x - frente * 0.5, fondo * -0.5, translate_z - alto * 0.5);

    /// render model....
    glPushMatrix();

    for (int volNo = 0; volNo < [self.modeloOptimo.arr_volumenes count]; volNo++) {

        VolumenOptimo *volOp = self.modeloOptimo.arr_volumenes[volNo];
        glLoadName(volNo);
        volOp->verProblemas = false;
        [volOp drawVolumen];
    }

    glPopName();
    glPopMatrix();

    // Flush view.
    glFlush();

    hits = glRenderMode(GL_RENDER);
    processHits (hits, selectBuf);
} // Fin de drawRect.

Always hits = 0, and selectBuf is empty.

Any idea. thanks

Menio
  • 61
  • 7
  • This is very old functionality. I've never seen it worked. You should use "geometric" picking by casting a ray into your scene. – Mr D May 01 '17 at 06:25
  • I resolve my problem retrieving the color of the pixel at click position, I render the scene twice, one with a white background color and a unique color for every object that I need test, and before render as anormal. Works fine. OpenGl in Mac as become obsolete, buy I need used because Metal is so complicated to learn and is difficult find a good tutorial. – Menio May 02 '17 at 15:39

0 Answers0