glText
glText copied to clipboard
Enabling depth test causes text to not draw even when is the only draw call
Adding "glEnable(GL_DEPTH_TEST)" (when using GLEW) causes the text to not be rendered. This can be recreated by running the "simple.c" example, and adding the function call:
...
//Used GLEW here but should be the same for GLAD
if (glewInit())
{
fprintf(stderr, "Failed to load OpenGL functions and extensions\n");
glfwTerminate();
return EXIT_FAILURE;
}
glfwSwapInterval(1);
//Can insert here]
glEnable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
if (!gltInit())
{
fprintf(stderr, "Failed to initialize glText\n");
glfwTerminate();
return EXIT_FAILURE;
}
...
I found this can be fixed/hacked around by tweaking the vertex shader source to set the Z coordinate to -1.0:
static const GLchar* _gltText2DVertexShaderSource =
"#version 330 core\n"
"\n"
"in vec2 position;\n"
"in vec2 texCoord;\n"
"\n"
"uniform mat4 mvp;\n"
"\n"
"out vec2 fTexCoord;\n"
"\n"
"void main()\n"
"{\n"
" fTexCoord = texCoord;\n"
" \n"
" // Updated gl_Position to account for depth test\n"
" vec4 ndc_pos = mvp * vec4(position, 0.0, 1.0);\n"
" gl_Position = vec4(ndc_pos.x, ndc_pos.y, -1.0, 1.0);\n"
"}\n";
Is this the intended behavior?