Combining glBlendFunc and glBlendEquationOES calls

Hi all,

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

To render my graphics normally, I call:

glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glBlendEquationOES(GL_FUNC_ADD_OES);

To render additive, I do this:

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

And to render with multiply, this:

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:

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!

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:

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: