Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

You can see most of my source code in this question: Instead of the specified Texture, black circles on a green background are getting rendered. Why?

Now I have the problem, that my texture has a white outline on its transparent parts. After googling and setting up glBlendFunc, the outline just got "softer".

This is how it looks like:

Teh bug

This is how I now setup OpenGL:

    public static void SetupGL()
        GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

        GL.Hint(HintTarget.PerspectiveCorrectionHint, HintMode.Nicest);

share|improve this question
Perhaps setting textures to be nearest instead of linear. Also, make sure your texture does not actually have a outline. – Byte56 Nov 20 '12 at 19:53
setting the Filters to Nearest solved it, thanks :) – vinzBad Nov 20 '12 at 20:07
up vote 6 down vote accepted

You should use pre-multiplied alpha for transparent textures that you intend to do alpha blending on. That will solve the color bleeding you're seeing.

First, make sure to multiply the RGB values of your texture with the A.

Second, use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) as the blend mode.

share|improve this answer
how do I accomplish this? should I loop through all pixels of my image and multiply them? I use a .png, I thought it already has premultiplied alpha? – vinzBad Nov 21 '12 at 15:46
PNG stores unassociated (non-premultiplied) alpha. You'll have to premultiply the pixels yourself after loading, before calling glTexImage2d. Loop through the pixels and multiply (color.rgb *= color.a). – ccxvii Nov 21 '12 at 16:12

You should try setting your textures to GL_NEAREST. It looks like you're using GL_LINEAR which could make your textures not be "crisp" on the edges where you want them to be.

share|improve this answer
This isn't a long-term solution and will look ugly once the sprite starts moving, especially when it gets bigger. Premultiplying alpha or choosing an appropriate background color will work much better in this case. – snake5 Nov 21 '12 at 15:18
@snake5 Good plan. – Byte56 Nov 21 '12 at 15:20
Just do little OpenGL I thought, 2D would be easy I thought :( now stuff gets strange... – vinzBad Nov 21 '12 at 16:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.