Multipass GL_ARB_multitexturing

Need more help guys. Previously I was successful in multitexturing two textures: a base texture which covers an entire polygon and a decal which appears in a small area over the same polygon by using glTexEnv(,GL_DECAL).

So I thought what happens if I want to put on a base texture and two decals. My video adapter (Geforce MX) has two texture units. So I’ll have to do this in two passes.

glClearColor( gray )
enable alpha testing
glAlphaFunc( GL_GREATER, 0.5 )

// Pass number one
glActiveTexture( unit 0 )
glBindTexture( base texture )
glTexEnv(,GL_DECAL)
enable texturing
glActiveTexture( unit 1 )
glBindTexture( 1st decal )
glTexEnv(,GL_DECAL)
enable texturing
draw quad

// Pass number two
glActiveTexture( unit 0 )
glBindTexture( 2nd decal )
glTexEnv(,GL_DECAL)
glActiveTexture( unit 1 )
glBindTexture( 0 ) // unbind texture
disable texturing
draw quad

disable alpha testing

The base texture and 1st decal has been wiped out (all white) and only my 2nd decal appears. What happened?

Inserting glFlush() after pass one did not help.

Technically, not even the second texture (tex unit 1) should be drawn, cause GL_DECAL==GL_REPLACE - so it should wipe out the first (tex unit 0) texture… the third decal texture is drawn over the quad as well and then replaces whatever is in the color buffer. Try using GL_MODULATE instead for the second pass and see what happens.

GL_REPLACE != GL_DECAL

When the alpha channel of a texture is fully opaque, they are the same. Otherwise they are different.

GL_DECAL is blended in with the previous texture unit based on its alpha. GL_REPLACE simply replaces all information from the previous texture unit, including alpha.

The reason you are seeing all white is because the background color of the quad is showing through your decal texture on the second pass. This means that to OpenGL, your quad is not transparent at all.

Setting your mode to GL_REPLACE or GL_MODULATE will fix it.

j

Thanks for the tip. GL_REPLACE & GL_MODULATE do work for the 3rd decal. OK, so one base texture and two decals works … how 'bout one more decal?

pass1.unit0.replace <-- base texture
pass1.unit1.decal <-- 1st decal
pass2.unit0.replace <-- 2nd decal
pass2.unit1.decal <-- 3rd decal
Didn’t work. 2nd decal OK. Can’t see 3rd decal. Ahhhhhh

I’ve also tried these variations for pass2
unit0.replace = not visible // gets crushed by 3rd decal
unit1.replace = visible

unit0.replace = not visible
unit1.modulate = not visible

unit0.modulate = visible
unit1.decal = not visible

unit0.modulate = not visible
unit1.replace = visible

unit0.modulate = not visible
unit1.modulate = not visible

I think those are all the possible combos. Can you guys help me one more time and I swear I won’t ask for help again … until the next time I need help.

Originally posted by j:
[b]GL_REPLACE != GL_DECAL

When the alpha channel of a texture is fully opaque, they are the same. Otherwise they are different.
[/b]

Oops… of course you’re right.
Sorry 'bout the wrong info