0
votes

I have an array of textures for model rendering in OpenGL. This array holds diffuse and specular textures. Since some meshes don't have a specular texture, I simply bind the NULL texture to my specular sampler after each rendering, and I only bind one if the mesh has a specular texture. However, I still see specular textures on meshes that don't have one.

This is my code for rendering
materialIndices holds the index of the texture in the array, if the mesh does not have a specular texture
the index is -1
texture unit 0 for diffuse
texture unit 2 for specular

void CModel::render()
{
    if (!loaded)    return;
    int numMeshes = meshSize.size();
    for (int i = 0; i < numMeshes; i++)
    {
        int matIndex = materialIndices[i][0];
        textures[matIndex].bind(0);
        int specIndex = materialIndices[i][1];
        if (specIndex >= 0) textures[specIndex].bind(2);
        glDrawArrays(GL_TRIANGLES, meshStartIndices[i], meshSize[i]);

        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, NULL);
    }
}
1
is this the old opengl without shader? - Irrational Person
You should do glBindTexture(GL_TEXTURE_2D, 0). NULL is a pointer type, but glBindTexture accepts an integer. - Colonel Thirty Two

1 Answers

4
votes

I think problem is in this line:

glActiveTexture(GL_TEXTURE2);

You said that you use texture units 0 and 1, but here you reset the texture unit 2. Maybe it is just a typo?