Discoloration in OpenGL

I use OpenGL for drawing in 2D. I am 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 the reverse z-order. However, I have strange color changes. Here is an example of something that should smoothly fade from one image to another (in fact, the images in this particular case are inactive, but this will not always happen (which means no, I can’t just not have alpha)): Strange discoloration from alpha blending

See the gray spot in the middle? This patch is not in any of the source PNGs. Does anyone know what causes this and how to fix it? Perhaps a completely different alpha strategy?

EDIT: For reference, here are two mixed textures:

enter image description here

+7
source share
3 answers

Are there any changes if you use this as a blending function?

 glBlendFunc(GL_SRC_ONE,GL_ONE_MINUS_SRC_ALPHA); 

EDIT / SOLUTION:

The resulting alpha in PNG was the culprit. Alpha would need to be separated from RGB in order to fix the image and remove the gray artifact (for more details see the Comment Chain)

+2
source

If your GL_TEXTURE_ENV is the standard GL_MODULATE , you may have some old color state floating around.

Try resetting it with glColor3ub(255,255,255) before rendering the texture geometry.

0
source

Now I am wildly guessing here, but if we exclude Z-fighting and color modulation, it could be some kind of filtering artifact. To quickly switch the test between

 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 

and

 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

if the effect changes between the two of you, some filtering somehow ruined your coloring. Decision. Use mipmaping and generate mipmap levels using the downsampling method, which preserves the desired functions. The gluBuildMipmaps standard uses a pretty dumb window filter, so don't use it.

0
source

All Articles