2

I have set up a quick 2D rendering system using OpenTK and OpenGL for a game. I have set up transparency using:

GL.Enable(EnableCaps.Blend);
GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);

However, whenever I go to draw (the texture is a png file loaded with System.Drawing), it only blends with the color I clear at the start of the draw call:

img

I just ended up switching to MonoGame, as it's 2D rendering has already been sufficiently tested

CallumDev
  • 239
  • 1
  • 9

1 Answers1

2

Looks like you're not drawing in the proper order. To get correct blending, you need to sort your polygons from back to front, so that anything 'behind' gets drawn first.

Based on that picture though, you might be better served with just using alpha testing instead of blending. Alpha test just discards pixels with alpha less than a threshold. It's less expensive than blending and you don't need to sort objects to use it. You only need blending when you want to use semi-opaque objects (alpha between 0 and 1).

Tim
  • 35,413
  • 11
  • 95
  • 121