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);
}
}
glBindTexture(GL_TEXTURE_2D, 0)
.NULL
is a pointer type, butglBindTexture
accepts an integer. - Colonel Thirty Two