In the code below I have a uniform variable named "vw_matrix" used in the calculation for gl_Position. When I run my program, a rectangle gets printed to the screen.
#version 330 core
layout (location = 0) in vec4 position;
uniform mat4 pr_matrix;
uniform mat4 vw_matrix = mat4(1.0); // Rectangle!
uniform mat4 m1_matrix = mat4(1.0); // No rectangle!
uniform mat4 mmmmm = mat4(1.0); // No rectangle!
uniform mat4 test = mat4(1.0); // Rectangle!
uniform mat4 aaa = mat4(1.0); // No rectangle!
void main()
{
gl_Position = pr_matrix * position * vw_matrix;
}
If instead I put "m1_matrix" in the gl_Position line instead of "vw_matrix". The rectangle no longer appears. I'm not getting any GLSL compile errors.
void main()
{
gl_Position = pr_matrix * position * m1_matrix;
}
There are no calls to glUniformMatrix4fv changing the value "m1_matrix". It has the same value as "vw_matrix" so for some reason it must not be initializing.
I did some experimenting, it won't set a uniform variable if it starts with a certain letter and "m" is one of those letters. Anything that starts with a "v" or "t" works fine. I can't make this up!
Is there anything I should double check/post or is this just a rather bizarre bug? The full code is available at https://github.com/nduplessis11/Freeze
I'm running on Linux Mint 17.1 and my GL_VERSION is "OpenGL 4.4 13374 Compatibility Profile Context 15.20.2013". My video driver is AMD's fglrx version 15.200
UPDATE: Ok, I found a bug in my main program in a function that retrieves the location of a uniform.
GLint Shader::getUniformLocation(const GLchar* name)
{
// This is a very slow operation, optimize later.
glGetUniformLocation(m_ShaderID, name);
return 0;
}
This was causing 0 to be passed as the location for glSetUniform* calls. I'm not sure how, but fixing this function stopped the unpredictable behavior when initializing uniform variables from within the shader program. I'm still going to take Trevor's advice and set them from within my main program.