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 2 of 2

Thread: Combining glBlendFunc and glBlendEquationOES calls

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    1

    Combining glBlendFunc and glBlendEquationOES calls

    Hi all,

    First off, I'm not too experienced with OpenGL.

    To render my graphics normally, I call:
    Code :
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glBlendEquationOES(GL_FUNC_ADD_OES);

    To render additive, I do this:
    Code :
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    And to render with multiply, this:
    Code :
    glBlendFunc(GL_ZERO, GL_SRC_COLOR);

    It all works fine... UNLESS I am trying to render to a framebuffer. When that happens, dark outlines appear where alpha is translucent. So, to fix that, when I want to render normal, I do this:
    Code :
    if (!gIsRenderToTexture)
    {
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
        glBlendEquationOES(GL_FUNC_ADD_OES);
    }
    else
    {
        glBlendFuncSeparateOES(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
        glBlendEquationSeparateOES(GL_FUNC_ADD_OES,GL_FUNC_ADD_OES);
    }

    And that works fine on newer systems. But on less powerful machines, like a Kindle Fire, I still get that dark rim when rendering to framebuffer. Even worse, on another popular but low-power tablet, running KitKat, my additive/multiply effects never turn off.

    Can anyone help me out with this? I'm trying to make RenderNormal(), RenderAdditive(), and RenderMultiply() functions that work on even older implementations of OpenGL, and can branch as necessary for whether I'm rendering to a framebuffer or not.

    I assume I'm not understanding how glBlendFuncSeperate and glBlendFunc juggle eachother (and newer GL I guess just handles it) so for that reason my additives, etc, are not turning off when I render to a framebuffer... but I have no idea what I should put in there to disable it (everything I try makes things worse).

    Thanks in advance!

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,176
    Sure sounds to me like you need to use pre-multiplied alpha (ONE,ONE_MINUS_SRC_ALPHA) blend factors set using the standard glBlendFunc() with the standard, default glBlendEquation (ADD). That should be commonly supported.

    It's also not obvious why for your render-to-texture you're doing conventional alpha blending for RGB and pre-multiplied alpha blending for only alpha.

    I'd suggest you read this:

    * Premultiplied Alpha

    particularly after your comments about dark outlines, paying specific attention to the "halo" references.

    Tom's also got a follow-on post you might want to read here:

    * Premultipled alpha part 2

Posting Permissions

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