1

In my Opengl Application (lwjgl) I enabled alpha blending like this:

GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

The result, when drawing two gradient circles, looks like this:

enter image description here

How can this be? (The black overlap is transparency actually...)

T_01
  • 1,256
  • 3
  • 16
  • 35
  • Which of the two circles did you draw first? When blending, you need to render your geometry back to front. – Reto Koradi Jun 03 '14 at 14:06
  • how can i do this? The one who is "over the other" is the one rendert first. – T_01 Jun 03 '14 at 14:12
  • 3
    You need to sort your objects by their depth, and then draw them back to front. I wrote a lengthy overview on various approaches for rendering transparency in this answer: http://stackoverflow.com/questions/23280692/opengl-es2-alpha-test-problems/23283256#23283256. – Reto Koradi Jun 03 '14 at 14:47
  • Do gradient circles use texture? – Unick Jun 04 '14 at 13:59
  • no. im calculating them in the fragment shader, like this: color = vec4(red, green, blue, (1.0 - distanceTo00 / 1.0)) – T_01 Jun 04 '14 at 14:01
  • Err, what is the point of dividing `distanceTo00` (or anything for that matter) by a constant **1.0**? In any case, you need to draw the sphere in the back first. – Andon M. Coleman Jun 05 '14 at 05:09
  • Err, the thing is I want to have a gradient? ^^ 1.0 is the radius of the sphere. – T_01 Jun 05 '14 at 05:34
  • @T_01: That does not change the fact that division by **1.0** does absolutely nothing. – Andon M. Coleman Jun 08 '14 at 03:57
  • yes, but its the radius of the sphere xD It's just against the effect, if i see this code in 10 years and ask, "shit, what was im doing here..", like this i know i divide through the circles radius, – T_01 Jun 12 '14 at 18:06
  • By the way, i couldnt fix it yet.. – T_01 Jun 12 '14 at 18:07

1 Answers1

0

I had sort of the same problem, try glDepthFunc(GL_LEQUAL) if all your vertices are on the same plane.

rafoo
  • 1,506
  • 10
  • 17