Texture Sprite giving Depth Test Artifacts

Hello. I’m experiencing problems drawing the following:

A transparent square, textured with an image that has a few fully transparent pixels. Such as a 2D game sprite.

I have successfully drawn the square with the image. But I am experiencing some depth-test related artifacts.

In my scene, there is a combination of 2D texture sprites and 3D
geometry. The scene is very dynamic, so the positions of the sprites and geometry constantly change.
When a 2D texture sprite is closer to the camera than a 3D cube, a square (with the same color set by glClearColor()) appears around the texture image, and in front of the cube. I am looking to have the cube appear through this ‘invisible square’, so that only the texture image appears in front.

In the image you can see the pink (what look like squares) but these are really the cubes. Also on the right you can see the heart icon used for the texture sprite. The depth testing artifact that I am talking about is the black square around the heart.

The reason I believe this is happening is because since depth testing is enabled, the square holding the texture sprite is covering whatever is behind it. However when I disable depth testing, the cubes will create more unwanted artifacts. And the hearts will display behind/inside the cubes, rather then in front.

What I am aiming for, is for the pink cube to show through where the heart itself does not cover up.

Thanks in advance, Nick.

Have you enabled blending? Otherwise the heart won’t being drawn transparent. Try something like


before drawing the heart.