0

我正在使用以下代码为 Open GL 呈现 .h 文件。然而,最终的结果是三角形而不是全部。请看附图。谁能指导我为什么会这样。因为我是 Open GL 的新手。在此处输入图像描述

我想开发一个应用程序 - https://itunes.apple.com/us/app/mclaren-p1/id562173543?mt=8

- (void)renderFrameQCAR
{
    [self setFramebuffer];

// Clear colour and depth buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Render video background and retrieve tracking state
QCAR::State state = QCAR::Renderer::getInstance().begin();
QCAR::Renderer::getInstance().drawVideoBackground();

//NSLog(@"active trackables: %d", state.getNumActiveTrackables());

if (QCAR::GL_11 & qUtils.QCARFlags) {
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_LIGHTING);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}

glEnable(GL_DEPTH_TEST);

// We must detect if background reflection is active and adjust the culling direction. 
// If the reflection is active, this means the pose matrix has been reflected as well,
// therefore standard counter clockwise face culling will result in "inside out" models. 
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
if(QCAR::Renderer::getInstance().getVideoBackgroundConfig().mReflection == QCAR::VIDEO_BACKGROUND_REFLECTION_ON)
    glFrontFace(GL_CW);  //Front camera
else
    glFrontFace(GL_CCW);   //Back camera

for (int i = 0; i < state.getNumTrackableResults(); ++i) {

    // Get the trackable
    const QCAR::TrackableResult* result = state.getTrackableResult(i);
    const QCAR::Trackable& trackable = result->getTrackable();
    QCAR::Matrix44F modelViewMatrix = QCAR::Tool::convertPose2GLMatrix(result->getPose());

    // Choose the texture based on the target name
    int targetIndex = 0; // "stones"
    if (!strcmp(trackable.getName(), "chips"))
        targetIndex = 1;
    else if (!strcmp(trackable.getName(), "tarmac"))
        targetIndex = 2;

    Object3D *obj3D = [objects3D objectAtIndex:targetIndex];

    // Render using the appropriate version of OpenGL
    if (QCAR::GL_11 & qUtils.QCARFlags) {
        // Load the projection matrix
        glMatrixMode(GL_PROJECTION);
        glLoadMatrixf(qUtils.projectionMatrix.data);

        // Load the model-view matrix
        glMatrixMode(GL_MODELVIEW);
        glLoadMatrixf(modelViewMatrix.data);
        glTranslatef(0.0f, 0.0f, -kObjectScale);
        glScalef(kObjectScale, kObjectScale, kObjectScale);

        // Draw object
        glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
        glTexCoordPointer(2, GL_FLOAT, 0, (const GLvoid*)obj3D.texCoords);
        glVertexPointer(3, GL_FLOAT, 0, (const GLvoid*)obj3D.vertices);

        glVertexPointer(3, GL_FLOAT, 0, MclarenInfoVerts);
        glNormalPointer(GL_FLOAT, 0, MclarenInfoNormals);
        glTexCoordPointer(2, GL_FLOAT, 0, MclarenInfoTexCoords);

        // draw data
        glDrawArrays(GL_TRIANGLES, 0, MclarenInfoNumVerts);


    }
#ifndef USE_OPENGL1
    else {
        // OpenGL 2
        QCAR::Matrix44F modelViewProjection;

        ShaderUtils::translatePoseMatrix(0.0f, 0.0f, kObjectScale, &modelViewMatrix.data[0]);
        ShaderUtils::scalePoseMatrix(kObjectScale, kObjectScale, kObjectScale, &modelViewMatrix.data[0]);
        ShaderUtils::multiplyMatrix(&qUtils.projectionMatrix.data[0], &modelViewMatrix.data[0], &modelViewProjection.data[0]);

        glUseProgram(shaderProgramID);

        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.vertices);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.normals);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)obj3D.texCoords);

        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, [obj3D.texture textureID]);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
        glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);

        glVertexPointer(3, GL_FLOAT, 0, MclarenInfoVerts);
        glNormalPointer(GL_FLOAT, 0, MclarenInfoNormals);
        glTexCoordPointer(2, GL_FLOAT, 0, MclarenInfoTexCoords);



        // draw data
        glDrawArrays(GL_TRIANGLES, 0, MclarenInfoNumVerts);


        ShaderUtils::checkGlError("EAGLView renderFrameQCAR");
    }
#endif
}

glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);

if (QCAR::GL_11 & qUtils.QCARFlags) {
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
} 
#ifndef USE_OPENGL1
else {
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);
}
#endif

QCAR::Renderer::getInstance().end();
[self presentFramebuffer];
}
4

1 回答 1

0

好的。我发现了这个问题。碰巧我的设计师给了我一个四边形渲染的文件,其中 Vuforia-Qualcomm-Unity 等仅识别三角化的 .obj。对于任何被困在这里的人:) 让你的设计师知道渲染三角而不是四边形。

于 2013-09-08T15:53:09.403 回答