# Problem with transparent textures in SFML

I have been told that this is kind of a common problem with transparent textures, but didn't get any further information on how to solve it.

In my code, I'm trying to render this texture (a square with rounded corners, where rounded corners have some alpha)

What I get instead is this

Notice those greyish places on the corners of the textures - where rounded corners are supposed to be.

What could be causing this? I have a pure-white texture, so I don't expect a single pixel to get any darker than the background. All pixels should have at least the color of background, but as you can see, there is something darker.

Zoomed even more:

Any help would be highly appreciated.

• Did you tried other textures with alpha channel? Maybe there is really a border – Ahmet Zambak Jan 6 '16 at 21:42
• Yes, and the thing is even worse with some other shapes. prntscr.com/9n21fb – user35443 Jan 7 '16 at 6:01

It looks like the color values are premultiplied with the alpha but are rendered with the non premultiplied blending factors.

This makes the color of any texels with alpha < 1 darker than they should be.

For premultiplied alpha textures blending factors should be:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);


You can test this by making your white rounded rectangle texture 50% opaque (the actual texture, not the vertex colors) and see if it makes a white/light background darker.

The usual factors (glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);) will cause this darkening on premultiplied textures. A similar issue happens with linear interpolation of color when textures are not premultiplied.

• I tried what you said and yes, they are darker. prntscr.com/9n24iv However, I didn't quite understand where the problem actually lies. What could I do to make it right? – user35443 Jan 7 '16 at 6:19
• try calling glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); before drawing your quads. It's the proper blending mode for premultiplied alpha textures. You can search the web for "premultiplied alpha" to find a large number of blog post and tutorials on the topic. Everyone needs a few different explanations on this topic before it clicks even if the solution is simple. – Stephane Hockenhull Jan 7 '16 at 13:24