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).
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?
glColorMask(O, 1, 1, 1);
works, but i was hoping to still be able to set alpha values as well… humph…
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
Its backarsed but works, marvellously. thanks