PDA

View Full Version : Not increasing alpha value in frame buffer



hockeyman
11-16-2012, 07:43 AM
Now it works like that:


Draw vertices array to framebuffer (framebuffer contents is black color, drawable quads (from vertices array) has white textures with various alpha values)
If in same place is drawed two quads who's texture's alpha is 0.5, that place has white quad with 1.0 alpha



How to do so that if the place where I draw a textured quad with 0.5 alpha already has half-opaque white quad, don't add its alpha value to it (leave it white with 0.5 alpha)? And if I draw textured quad with 0.7 alpha on it, change that place's alpha to 0.7. And if I draw textured quad with for example 0.3 alpha on it, ignore it?

So it should look like this:
(number is white color's alpha value)
(where 0.0 it is black and where number is not 0.0, it means that there is drawn white quad with alpha equal to number represented in brackets)

in the beginning my image looks like this:
(0.0)(0.0)(0.0)(0.0)

after drawing this image:
(0.0)(0.0)(0.5)(0.0)

on it I should get:
(0.0)(0.0)(0.5)(0.0)

after drawing this image:
(0.0)(0.0)(0.3)(0.0)

on top of it, it's alpha is ignored because it is smaller than one that already is there and I get:
(0.0)(0.0)(0.5)(0.0)

after drawing this image:
(0.0)(0.0)(0.7)(0.0)

on top of it, I get:
(0.0)(0.0)(0.7)(0.0)

tonyo_au
11-17-2012, 05:29 PM
If in same place is drawed two quads who's texture's alpha is 0.5, that place has white quad with 1.0 alpha

read this carefully
http://www.opengl.org/sdk/docs/man/xhtml/glBlendEquation.xml

It is important to fully understand how successive draw functions with an alpha value effect a pixel

hockeyman
11-21-2012, 06:38 AM
Thank you. That helped me allot. :)

hockeyman
11-22-2012, 06:06 AM
So now I use


glBlendEquationSeparate(GL_FUNC_ADD, GL_MIN);

and it works fine with the circumstances I described above. But the continue of question would sound like that:

My vertex-array depends on user mouse events. And if user drags a mouse, vertices are being recorded to vertex array and drawn to screen. And how now to do so that, when mouse is up, save the state, and if user drags mouse again over the place where vertices have been already drawn earlier, increase the alpha value, and if he drags mouse over the place where vertices have been already drawn in this mouse-drag period (after first mouse-up but before second), don't increase alpha value?

tonyo_au
11-22-2012, 02:16 PM
I am not sure what outcome you want. If the alpha value change is only effecting the vertex just change that alpha value in the vertex structure and redraw the screen.

hockeyman
11-23-2012, 05:44 AM
I will explain outcome that I want.

So, user presses and drags mouse (draws). It acts like that:

mouseDown and mouseDragged events is being executed. Their coordinates are written to vertex-array (from every event I create 4 coordinates so that I could get quad), and then vertex array is drawn to framebuffer, and framebuffer is drawn to screen.

If drawable object opacity is set to 0.5, no matter how many times I draw it it still stays at 0.5. And I want so that:

For example I set drawable object opacity to 0.5, I draw one stroke (one mouseDown and much mouseDragged events). It should work like it works now, no matter how many times quad overlaps itself it's opacity stays 0.5. Then mouse is up (mouseUp event executed). And I press mouse and draw next stroke with same opacity setted. If current stroke overlaps stroke that has ben drawn earlier, that place should have 1.0 opacity, and if it overlaps itself opacity should stay 0.5.

tonyo_au
11-23-2012, 06:44 PM
There is no OpenGL blend to do what you ask as it makes no sense - for example if you opacity was .75; it would imply the overlaps area would be 1.5 (0.75 + 0.75); but the maximum value is1.0.

The standard blend will give you a slightly lighter area where the quads overlap approaching solid the more you overlap (assuming your colour for all quads is the same).

For example with an opaciity of 0.5 and a background of (0,0,0,1).
where the quads do not overlap the red conponent would be r*0.5 and where they overlap (r*0.5)*0.5 + r*0.5 -> r * 0.75
if 3 overlapped the red component in the overlap would be ((r*0.5)*0.5 + r*0.5) * 0.5 + r*0.5 -> r * 0.875

hockeyman
11-26-2012, 05:06 AM
That would be OK, if I could find some way how to set one glBlendEquation for same mouseDown/mouseDragged event and other for quads that have been drawn earlier. If I would draw everything to brushframebufer like that:

1. bind framebuffer_temp and set glBlendEquationSeparate(GL_FUNC_ADD, GL_MIN);
2. draw currently mouse-events vertices
3. unbind framebuffer_temp
4. bind framebuffer
5. reset glBlendEquation to default
6. draw framebuffer_temp texture to it (without clearing earlier content)
7. unbind framebuffer

it should work, doesn't it?


EDIT: Yes, it works! Thank you very much :)