I am blending my textures to create a mask and then texture the quad according to the mask. But now I want to be able to change the color of the object on the fly while it is masked. If I change the color to a whole color eg: 1,0,0 - red. Then it works fine. But when I try something like: 0.5,0,0. Then it decides it wants to show the whole quad and not just the masked bit. So it shows the black around the edge, which I had removed with the mask.

Any help would be appreciated.


a bit underspecified :slight_smile:

i mean, you have a texture (wich kind ? luma rgb alpha…) wich is layered onto a quad (environment mode ? replace modulate… the last i suppose)

what do you exactly mean with “masking” ?

when it works with full red, what do you see ?
and the dark red, where did it end up ?

Ah, ok. Detail you need, detail you shall have.

The textures are in RGB format, textured onto a quad using the Modulate environment mode.

By masking, I mean I have 2 images. One with a black image and white background (the mask) and the actual texture which is coloured normally but with a black background.

I am first setting the blending mode to:

Then I am binding my mask.

Then I am changing the blending mode to:

Then I am binding my texture.

These are both being binded to the same quad, in that order.

When It works with full red, I see the image as it should appear, only red. But when I set it to dark red, I see the quad texture as dark red, only now it shows the black outline which was supposed to be erased with the mask.

i should see some screenshots but… let’s try.

ok the algorithm is a two-pass one, no multitexturing.

the algorithm you described is:

glColor3f( 1,0,0 );  // hot red
glBlendFunc( GL_DST_COLOR, GL_ZERO );  // modulating blend
glBind( GL_TEXTURE_2D, mask );
glBlendFunc( GL_ONE, GL_ONE );  // additive blend
glBind( GL_TEXTURE_2D, normal );

GL_DST_COLOR, GL_ZERO translates to d = s*d + 0
wich is like modulation, and it means that if you start with a black background, like with glClearColor( 0,0,0,0 ), after any rendering all you get is black: what color is in the framebuffer before this stage ?

it is uncommon to start modulate-blending without a well defined framebuffer contents… maybe the bug is this.

to go on, i suppose fb is now white.

after the first stage, you should end up with a black image surrounded by a white background (your mask)
if you’ve choosen the hot red base color, you’ll get black over hot red.

second stage:

GL_ONE, GL_ONE -> d = s + d
all you render is summed up in the framebuffer.
drawing anything black won’t show up, it will keep the previous frambuffer pixel’s color.

the outcome of the second stage will be a colored non-mask-texture superimposed to the colored mask.

if you’re still with the hot red, your final effect will be red image with red bg.

but, in case your fb has black background, the first stage won’t participate in the final outcome.
black before, black after.
you’ll only see the second pass, thus red image in black background.

in the end, by controlling the base color, you control the background color AND the texture-modulating color.

but all depends on the previous fb contents due to the GL_DST_COLOR, GL_ZERO

maybe is not the reply you asked for, but i hope it helps