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:
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:
- enable depth buffer
- render opaque geometry
- disable depth writes (
gldepthmask
) - enable alpha blending (as in op's code)
- 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
Post a Comment