Text rendering problems

why is that happening?
I rendering in order from back to front the other entities in the screen don’t act like this only a simple Rectangle mesh.

Disable depth testing before rendering text, that works for me. Also set your blend function to the following.


glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

That should solve this issue. Also make sure to render text after all the drawing in the scene is done. Don’t forget to enable the depth testing back once the text rendering is done.

if I do that the text will have black fills for the rectangle not?

No, disabling the depth testing forces the renderer to replace the pixels, and the blend function tells it to blend with existing pixels instead of overwriting completely. In case your font texture has a black background, then yes, and in that case you have two options:

Modify the font shader to discard on a black pixel.


if (texel.rgb == vec3(0, 0, 0))
    discard;

Or you can set the texel’s alpha to zero so it won’t be overwritten.


if (texel.rgb == vec3(0, 0, 0))
    texel.a = 0;

That should do what you are aiming for. An even simpler solution is to edit your font textures and save them as PNG images with transparent background. In that case, you can simply multiply the texel with a color vec4 to change the text color too.

thx for the help the depth test fucked up the things

What does that mean? Did it work or not?