How are color arrays and textures combined?

Hello,

this should be a fairly basic question but I’m having a hard time finding any answers on the interwebs.

I’m drawing a model, providing a texture as well as a color array, but I don’t understand how the two are being combined.

Is there some parameter where you set this up? I was assuming they’d be multiplied, but the results look fairly random, except when the texture is all white.


// Enable alpha blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

// Enable Vertex and Texture pointers
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

...

// vertices
glVertexPointer(3, GL_FLOAT, 0, cur->GetVertexBuffer() );

// texture
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
currentTexID = cur->GetGLTextureID();
glBindTexture(GL_TEXTURE_2D, cur->GetGLTextureID());
glEnable(GL_TEXTURE_2D);
glTexCoordPointer(2, GL_FLOAT, 0, cur->GetTextureCoordBuffer());

// color array
glEnableClientState( GL_COLOR_ARRAY );
glColorPointer( 4, GL_FLOAT, 0, cur->GetColorBuffer() );

// lighting
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnableClientState( GL_NORMAL_ARRAY );
glNormalPointer( GL_FLOAT, 0, cur->GetNormalBuffer() );

// draw it
glDrawArrays(GL_TRIANGLES, 0, cur->GetNumTriangles()*3 );

By default in OpenGL, the texture of your model will be multiplied (glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE)) by the color of the incoming fragment (the interpolated color you give at each corner of you triangle if you use glShadeModel(GL_SMOOTH)).


// Enable alpha blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

If your model is not fully opaque then this is ok.

In your code I see this glEnable(GL_COLOR_MATERIAL) but I don’t see a glColorMaterial call. Maybe this is the source of your problem (see the note section).