View Full Version : Blending -> resulting alpha pixel
07-09-2005, 08:48 AM
For a few days now I've been trying to achieve the following:
Drawing two quads on top of another in ortho, both with the color (255,255,255,128)... now to the tricky part... how do I blend the color from the second quad so that the resulting pixel would have the color (255,255,255,128) and not (255,255,255,255) as I got with ordinary blending. There must be some way to achieve this without having to use extensions... not that I know how to do I in that way either.
Well, if you want the color (255, 255, 255, 128) as the final result, and that is exactly the color of the two quads, then just diable blending completely, since the two quads already have the desired color.
Or, as I suspect, if that was just an example, and you really mean you want to treat RGB different than A, you can look at glBlendFuncSeparate/glBlendEquationSeparate. It allows you to specify different blending equations and factors for RGB and A.
07-09-2005, 10:55 AM
So there are no way to do this without using extensions?
To clarify what I want to do:
http://ariel.rsn.bth.se/img/1.png http://ariel.rsn.bth.se/img/2.png http://ariel.rsn.bth.se/img/3.png
2. Current result
3. Want this!
Well, I never suggested using any extensions. Seperate blending functions and factors have been in the core API since OpenGL 1.4.
Anyway, it's not really clear to me what you want. If you want the grey color as in the third picture, can't you draw that directly? Why do you have to use blending to combine several passes to get a result you already know what it should look like?
07-09-2005, 11:32 AM
I want the pixels of the "button" in this case - the entire system has to be quite dynamic, to look like it's a part o the window bellow - not like it's a seperate layer on top when the opacity of the whole window and it's component is bellow 1.0f. When the button is drawn I don't want OpenGL to add to the alpha channel - so that a combined color of 128,128,128,128 + 255,0,0,255 - would remain semi transparent (128) not 255 as it would be in this case. What I want it to do is to completely overlook the alpha cannel when doing the color addition, so that the opacity remains.
Ok, I think I understand what you want now. Tell me if I'm off on some details.
The thing you ask for, to not touch the alpha channel, can be done using glColorMask to prevent the alpha channel to be updated. However, judging by your description, I don't think this is what you really want.
So, my guess is that, at the moment, when you draw the button on the window, the button will appear to be a second layer ontop of the window layer. But you want the button to be a part of the window, and have the same transparency as the window itself. Is this correct?
I think this can be done using this blending mode.
glBlendFunc(GL_DST_ALPHA, GL_ZERO);This assumes you have a destination alpha channel, and that the window background is drawn first to set the general alpha channel for the window. The alpha channel for the button shouldn't matter, the transparency will be determined by the destination alpha. If buttons, or whatever other objects you have, can overlap, you may want to disable alpha channel writes as descibed above, or overlapping components will appear as multiple layers, not a single layer.
Another option could be to render the window and all it's content to a texture, and then draw everything as a single textured quad, with alpha channel depending on how transparent you want the window to appear. Then you don't have to care about tranparency when drawing the window content.
I hope I got the above correct, as I haven't tried it myself. :rolleyes:
07-09-2005, 12:42 PM
That is exactly what I'm trying to achieve. Although I can't get that combination to do what I want. Could be a screwup on my part though ;) . Well there's nothing more than playing arround with that combination. Would be nice to know if it's the right one...
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.