# LWJGL 3 - Random Sprites Don't Blend

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.

• 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)). – Andon M. Coleman Aug 7 '15 at 2:52
• 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? – Andon M. Coleman Aug 7 '15 at 2:56
• 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.) – Lolums Aug 7 '15 at 8:59