Multitexturing and colors

I have a problem with multitexturing and vertex colors. Suppose I have a triangle with colors for each vertex specified with glColorPointer (I use glDrawElements for drawing my primitives), and I want to multitexture it with two textures.

The first is a simple RGB (no alpha) texture, and the second a ARGB texture I want to combine with GL_DECAL (to mask out and blend certain areas to let the first texture show ‘through’)

Ok, now the problem is that since I set GL_MODULATE on the first texture unit and GL_DECAL on the second, the vertex colors will be ‘lost’. Sure, the areas where only the first texture is visible (where alpha is 0 in the second texture) is correctly colored since it modulates in the first texture unit. But the second unit’s GL_DECAL environment will ignore the vertex colors.

Thinking bout it, the most logical way to do multitexturing would be to use a final modulate on the primitive color and combined texture value AFTER all texture units have been combined, but since OpenGL takes the primitive color as input to the first texture unit this doesn’t seem possible.

What is the general solution to this problem (to get multitextured primitives with a decal texture ‘shaded’ with the vertex colors)?

Look up GL_COMBINE texture environment mode. It’s available standard in later GL implementations, and an extension on most cards for 1.1.

If that’s not sufficient, look into nVIDIA register combiners (for nVIDIA hardware) and ATI pixel shaders (for later ATI hardware).

I have the same problem but I don’t understand the solution is it something like:
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_COLOR,GL_COMBINE);
and how can I have GL_COMBINE
THANKS

GL_COMBINE is a TEXTURE_ENV_MODE just like DECAL and MODULATE. It’s available as an extension for OpenGL 1.1; look for ARB_texture_env_combine (or just look up GL_COMBINE in the 1.3 spec, which is the same thing only blessed by the ARB).

So the solution would be to setup the first texture unit to take ( tex0 * ( 1 - a1 ) + tex1 * a1 ) for the decal op, then the second unit to do the color modulate, i.e ( result_from_first_unit * col )? … and this requires GL_ARB_texture_env_crossbar or the nVidia combine4 extension(s) I guess.

thanks and can I change the color of the fisrt texture and 2nd texture separatly ?
so I want to have 1 glColor4f per vertex for the fisrt texture and an other (per vertex) for the 2nd texture
in order to have a gradient
Is it possible ??
thanks !!!

?? why this code do nothing ?

// TEXTURE-UNIT #0
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
// TEXTURE-UNIT #1
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_COLOR,GL_COMBINE_EXT);