Classic transparency problem with PNG

Hello!

Have been off this board for quite some time. So I am glad to finally having a reason to come back. :slight_smile: Of course it is that I am having a problem I am not able to fix myself.

I am currently developing with LibGDX. It is a 2D-side-scroller. I used black as the clearColor so far but changed it to white for testing purposes. I use background, foreground and decoration layers to draw tiles. Some tiles have transparency via alpha-channel in PNG-format. Now with the black clearColor it worked fine. But when I changed it to white it suddenly looked like this:

http://www.rm2k-tv.de/stuff/alphaProblem.png

So my questions are: As the vertical structures on the sides of the door belong to the deco layer, shouldn’t the background layer, which is drawn before deco layer, give the source color for the blending? Is the clearColor somehow a problem? What could solve the problem?
I have following line in my code:


		batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

This is fixed function, does this still affect rendering when using shaders? I found sources which said so.

To make it clear, my rendering routine for the map works this way:


	
	public void draw(SpriteBatch batch, float x, float y){
		drawBG(batch, x, y);
		drawFG(batch, x, y);
		drawDeco(batch, x, y);
	}

And drawDeco is where the transparent PNG is in.

Does someone have a clue? Is some information missing to see the problem? I will be glad if you can help me.

you’re right about the blending source colour. dont think that’s the problem.

i guess, the png images come with premultiplied alpha. random google : https://developer.nvidia.com/content/alpha-blending-pre-or-not-pre

what happens if you change it ?

So I don’t really get this in it’s full glory, but I changed the blendFunc to see what happens.
It was:

batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

Now it is:

batch.setBlendFunction(GL20.GL_ONE, GL20.GL_ONE_MINUS_SRC_ALPHA);

It looks like this with the latter code (don’t mind the different color tint):

http://www.rm2k-tv.de/stuff/alphaProblem2.png

So it looks like you could be right. I will test some more things now. Thank you very much for your great help so far, basil_. :slight_smile:
Still, if someone has more information, please let me know. I will let you know if the problem is solved and how.

So I guess the issue is really with the image source and the premultiplied alpha. I have some trouble really understanding all of this because it doesn’t behave as I expect it to, but I know a way to deal with it, which is just to leave the clearColor as black. :clue:

EDIT: Post went into wrong thread.