如何禁用此代码中的纹理?

How can I disable the texture in this code?

我在玩 Vuforia,它是 OpenGL 代码,但我真的不知道它们的作用。我只想禁用其中的纹理,因为我从 .obj 文件生成的代码不包含纹理文件。

我只是想让别人告诉我每个块的作用以及我如何清除纹理,所以我的模型是完全白色的(或者白色带有阴影,如果这很容易做到的话)。

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

// Render video background
[appRenderer renderVideoBackground];

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);

for (int i = 0; i < state.getNumTrackableResults(); ++i) {
    // Get the trackable
    const Vuforia::TrackableResult* result = state.getTrackableResult(i);
    Vuforia::Matrix44F modelViewMatrix = Vuforia::Tool::convertPose2GLMatrix(result->getPose());

    // OpenGL 2
    Vuforia::Matrix44F modelViewProjection;

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

    glUseProgram(shaderProgramID);

    glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)teapotVertices);
    glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)teapotNormals);
    glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid*)teapotTexCoords);

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

    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, augmentationTexture[i].textureID);
    glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE, (const GLfloat*)&modelViewProjection.data[0]);
    glUniform1i(texSampler2DHandle, 0 /*GL_TEXTURE0*/);
    glDrawElements(GL_TRIANGLES, NUM_TEAPOT_OBJECT_INDEX, GL_UNSIGNED_SHORT, (const GLvoid*)teapotIndices);

    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);

    VuforiaApplicationUtils::checkGlError("EAGLView renderFrameVuforia");
}

glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);

glDrawElements 调用似乎很重要,但是如果我不需要纹理,我传递什么?我是否启用和禁用 VertexAttribArray?那到底有什么作用?

最简单的方法是编辑使用白色纹理的着色器代码。它应该类似于用 vec4(1.0)

替换 texture2D(texture, coord)

或者,您可以使用 glTexImage2d 上传白色纹理,该纹理可以在包含以下数据的 1x1 缓冲区中创建:

GLubyte texdata[1 * 1 * 4] = {0xFF, 0xFF, 0xFF, 0xFF};