I'm using OpenGL to draw in 2D. I'm trying to overlay textures with alpha. I have done this:
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
And then I draw in reverse z-order. However, I'm getting strange discolorations. Here's an example of something that should smoothly fade from one image to another (in fact, the images are seamless in this particular case, but that won't always happen (so, no, I can't just not have alpha)):
See the grey patch in the middle? That patch is in neither of the source PNGs. Does anyone know what's causing this and how to fix it? Perhaps a completely different alpha strategy?
EDIT: For reference, here are the two textures being blended:
Is there any change if you use this as your blending function?
glBlendFunc(GL_SRC_ONE,GL_ONE_MINUS_SRC_ALPHA);
EDIT/SOLUTION:
Pre-multiplied alpha in the PNG was the culprit. Alpha needed to be divided back out of RGB to correct the image and remove the gray artifact (see comment chain for details)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With