0

我正在尝试在 NSOpenGLView 中实现拾取,但不起作用,这是代码。

我只渲染我需要选择的没有灯光的对象,并在正常渲染中渲染场景。

- (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.

始终命中 = 0,并且 selectBuf 为空。

任何想法。谢谢

4

0 回答 0