c++ - OpenGL blending: texture on top overlaps its pixels which should be transparent (alpha = 0) -


i drawing map texture and, on top of it, colorbar texture. both have alpha channel , using blending, set as

// turn on blending glenable(gl_blend); glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); 

however, following happens:

texture on top alpha channel imposes black pixels

the texture on top (colorbar) alpha channel imposes black pixels, don't want happen. map texture should appear behind colorbar alpha = 0.

is related blending definitions? how should change it?

assuming texture has alpha channel , it's transparent in right places, suspect issue rendering order , depth testing.

lets render scale texture first. blends correctly black background. render orange texture behind it, pixels scale texture have higher depth value , cause orange texture there discarded.

so, make sure render transparent stuff in front order, or farthest nearest.

without getting order independent transparency, common approach alpha transparency follows:

  1. enable depth buffer
  2. render opaque geometry
  3. disable depth writes (gldepthmask)
  4. enable alpha blending (as in op's code)
  5. render transparent geometry in farthest nearest order

for particles can away without sorting , it'll still ok. approach using alpha test or using alpha coverage multisample framebuffer.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -