PDA

View Full Version : Multitexturing and colors



arithon
04-28-2002, 04:37 AM
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)?

jwatte
04-28-2002, 11:14 AM
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).

IronRaph
04-28-2002, 12:48 PM
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_C OMBINE);
and how can I have GL_COMBINE
THANKS

jwatte
04-28-2002, 01:15 PM
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).

arithon
04-29-2002, 04:00 AM
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.

IronRaph
04-29-2002, 07:46 AM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif
Is it possible ??
thanks !!!

IronRaph
04-29-2002, 09:34 AM
?? 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_MO DULATE);
// 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_DE CAL);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_COLOR,GL_C OMBINE_EXT);