Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Not increasing alpha value in frame buffer

  1. #1
    Intern Newbie
    Join Date
    Jul 2012
    Posts
    41

    Not increasing alpha value in frame buffer

    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)

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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/x...ndEquation.xml

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

  3. #3
    Intern Newbie
    Join Date
    Jul 2012
    Posts
    41
    Thank you. That helped me allot.

  4. #4
    Intern Newbie
    Join Date
    Jul 2012
    Posts
    41
    So now I use

    Code :
    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?

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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.

  6. #6
    Intern Newbie
    Join Date
    Jul 2012
    Posts
    41
    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.

  7. #7
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    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

  8. #8
    Intern Newbie
    Join Date
    Jul 2012
    Posts
    41
    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
    Last edited by hockeyman; 11-26-2012 at 06:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •