0
\$\begingroup\$

Some of my sprites don't "Blend" in with tiles behind them Z-wise.

glEnable(GL_DEPTH_TEST);

Depth testing is enabled and works.

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

The blend function is above.

Below is a picture of four different instances of the application. As you can see, blending works on random sprites.

Why aren't some of the sprites blending?

An observation that I made is that when I move the sprites (layers 0 and 1) below (Z-wise) the button, you can see the sprites from the gaps left by letters (layer 10), yet the button itself (layer 9) doesn't show in that area. This is what I find the strangest.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Generally you want to disable depth writes for translucent layers, I don't see that happening here. Since you're using alpha blending and not alpha testing, those pixels that are blended away still produce depth values and that's not what you want most of the time (the entire tile, including translucent parts, will cause depth failure for things behind it). Alpha testing doesn't exist in modern GL, so you can potentially duplicate that behavior by using discard in a fragment shader (discard non-opaque fragments), or what seems a lot more sensible to me (glDepthMask (GL_FALSE)). \$\endgroup\$ – Andon M. Coleman Aug 7 '15 at 2:52
  • \$\begingroup\$ This doesn't fully explain the behavior I'm seeing, or I'd write an answer. Can you try what I've described and report back if anything improves? \$\endgroup\$ – Andon M. Coleman Aug 7 '15 at 2:56
  • \$\begingroup\$ The discarding of anything with an alpha value below 1.0 worked perfectly. However, glDepthMask(false) produced the following effect: prntscr.com/81u6e6 (Since I didn't know about discard before, I've decided to get rid of the alpha channel and discard that bright magenta colour instead. Thanks.) \$\endgroup\$ – Lolums Aug 7 '15 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.