Hi,
I am trying to use uniform variables in my shader but for some reason glGetUniformLocation always returns -1. I am mostly following Lazy Foo's tutorial. Here is the relevant code:
PointLineShader::PointLineShader() {
GLuint vertexShaderId = loadShader("Shader/pointLine.vert", GL_VERTEX_SHADER);
GLuint fragmentShaderId = loadShader("Shader/pointLine.frag", GL_FRAGMENT_SHADER);
programId = glCreateProgram();
glAttachShader(programId, vertexShaderId);
glAttachShader(programId, fragmentShaderId);
glLinkProgram(programId);
glDetachShader(programId, vertexShaderId);
glDetachShader(programId, fragmentShaderId);
glDeleteShader(vertexShaderId);
glDeleteShader(fragmentShaderId);
positionLocation = glGetAttribLocation(programId, "in_Position");
if (positionLocation == -1) {
printf("%s is not a valid glsl program variable!\n", "in_Position");
}
colorLocation = glGetAttribLocation(programId, "in_Color");
if (colorLocation == -1) {
printf("%s is not a valid glsl program variable!\n", "in_Position");
}
// this doesn't work
projectionMatrixLocation = glGetUniformLocation(programId, "projectionMatrix");
if (projectionMatrixLocation == -1) {
printf("%s is not a valid glsl program variable!\n", "projectionMatrix");
}
modelViewMatrixLocation = glGetUniformLocation(programId, "modelViewMatrix");
if (modelViewMatrixLocation == -1) {
printf("%s is not a valid glsl program variable!\n", "modelViewMatrix");
}
}
And the vertex shader:
#version 400
uniform mat4 projectionMatrix;
uniform mat4 modelViewMatrix;
in vec2 in_Position;
in vec4 in_Color;
out vec4 ex_Color;
void main(void)
{
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(in_Position.x, in_Position.y, 0.0, 1.0);
//gl_Position = projectionMatrix * modelViewMatrix * vec4(in_Position.x, in_Position.y, 0.0, 1.0);
ex_Color = in_Color;
}
To initialize openGL I am using SDL2 and glew. I noticed that I set the openGL version to 3.2 in SDL, but in the shaders I have "#version 400". If I change or remove it the shader won't compile.
I am not sure if it might be related, but textures also don't work right now even though I am using the same code as in my other program which uses SFML except for the image loading functions.