Blending and Masking

Hi all,

I have a blending question which has been making my head hurt a little, not really done blending before.

What I have is a texture mapped quad which takes up the whole window. I need to draw a smaller quad on top of that texture which takes the exact colour of the texture underneath. Then I remove a channel of colour e.g.

DrawGlTexture();

glEnable(GL_BLEND);
glBlendFunc(something, something);
glColorMask(FALSE,TRUE,TRUE,TRUE);
DrawGLQuad();
glColor3/4(something);
glDisable(GL_BLEND);

How do I get the quad to copy (through blending) the texture underneath??

The smaller quad will just be the same as the texture it is on top of minus the red colour channel for instance

Thanks

Gav

If i understand you correctly, you want to render a quad and where that quad gets rendered the framebuffer is supposed to get subtracted ie. the red channel.

I didn´t test it, but it might be possible to do it this way:

The blending equation is
color = src * srcfactor + dst * dstfactor

Since you only want to read the dst-color, but don´t want to add anything, you need to set srcfactor = 0 (GL_ZERO) and dstfactor = 1 (GL_ONE).

With your writemask set to filter the red channel this should work as expected.

The color and texture of your quad should be unimportant.

Hope that helps (and works).
Jan.

That does make sense but doesnt seem to work. After playing in photoshop i wondered if i can repicate what happens there, if i draw a red sqare on the image and then blend using a difference filter, it basically subtracts the redsqare from the image… now doing it in opengl. can i draw a red polygon and in blending subtract that from the underlying texture?

Ok,

glBlendFunc(GL_ZERO_GL_ZERO);
glColorMask(O, 1, 1, 1);

works, but i was hoping to still be able to set alpha values as well… humph… :frowning:

Originally posted by Gavin:
[b]Ok,

glBlendFunc(GL_ZERO_GL_ZERO);
glColorMask(O, 1, 1, 1);

works, but i was hoping to still be able to set alpha values as well… humph… :frowning: [/b]
That works??? I can´t believe it, because you multiply src and dst with zero, meaning, that you will write black into your framebuffer.

Damn, now i see my error.

Of course, if you read the image and write it back to the framebuffer, except for the red channel, then you don´t see a difference, because the red channel is already set, and you don´t modify it, so actually you don´t change anything.

What you want to do, is to reset a specific channel to 0. So, if you want to filter out the red channel, you actually want to set the red channel to 0 and leave the rest as is.

And this you can do even without blending:

glColorMask (true, false, false, false);
RenderBlackQuad ();

This way you leave green, blue and alpha unchanged, but set the red channel to zero (black).

I haven´t tried it, yet, but this time i´m sure about it :wink:

Jan.

Its backarsed but works, marvellously. thanks