Search code examples
c++opengl-estextures

How can I disable the texture in this code?


I am playing around with Vuforia, and it's OpenGL code, but I don't really know what everything does. I just want to disable the texture in this, as the code I generate from .obj files does not contain a texture file.

I simply want someone to tell me what each block does and how I can clear the texture, so my model is entirely white (or white with shadows, if that is easy to do).

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

The glDrawElements call seems important, but what do I pass if I don't need the texture? Do I enable and disable the VertexAttribArray? What does that even do?


Solution

  • Easiest way would be to edit the shader code that uses the texture to use white color. It should be similar to replacing texture2D(texture, coord) with vec4(1.0)

    Alternatively you can use glTexImage2d to upload a white texture which can created in 1x1 buffer containing following data:

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