Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discoloration in OpenGL

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)): Strange discoloration from alpha blending

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:

enter image description here

like image 642
andyvn22 Avatar asked Jun 06 '11 19:06

andyvn22


1 Answers

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)

like image 66
holtavolt Avatar answered Nov 11 '22 21:11

holtavolt