Question

I'm using the following to enable alpha blending

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

The transparency is taken from a texture which seems to work, using the simplest of fragment shaders:

void main(void) {
  gl_FragColor = texture2D(texture, texCoordOut);
}

While it blends nicely with the background color it doesn't work with other objects using the same alpha blending. I don't really know how to explain this so here's a picture:

alpha blending going wrong

What am I doing wrong?

Was it helpful?

Solution

Nothing wrong in your code. My guess is probably the order you draw each image makes the difference.For example if you draw images in the following order BGImage ,image1 , image2 and so on.

What opengl do is, it takes your draw call order for blending images. After drawing BGImage in framebuffer, then it blends image1 and framebuffer, then draws the result again in framebuffer. Then it blends image2 and framebuffer, then draws the result again in framebuffer and so on.

So if image1 overlaps image2, image1 blends with BGimage not with image2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top