View Full Version : Blending and Masking
04-13-2005, 02:31 PM
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.
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
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).
04-13-2005, 04:25 PM
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?
04-13-2005, 05:04 PM
glColorMask(O, 1, 1, 1);
works, but i was hoping to still be able to set alpha values as well... humph.... :(
Originally posted by Gavin:
glColorMask(O, 1, 1, 1);
works, but i was hoping to still be able to set alpha values as well... humph.... :( 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);
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 ;)
04-14-2005, 03:14 PM
Its backarsed but works, marvellously. thanks
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.