Can't set uniform value

I have the following vertex shader

#version 460 compatibility
layout(location = 0) in vec3 vertexPosition;
uniform mat4 modelViewMatrix;
uniform mat4 projectMatrix;
void main() {
  gl_Position = projectMatrix * modelViewMatrix * vec4(vertexPosition,1);
}

when trying to set value of the projectMatrix, I got an invalid operation error, what I’ve missed?

...
auto loc = glGetProgramResourceLocation(prog,GL_UNIFORM,"projectMatrix");
GLfloat proj[16] = {0};
glGetFloatv(GL_PROJECTION_MATRIX,proj);
// I'm sure loc is valid
// and prog has linked successfully
glProgramUniformMatrix4fv(prog,loc,16,false,proj);   // invalid operation
...

This says that you’re uploading to an array of 16 4x4 matrices. You aren’t; you’re only uploading to an array of one 4x4 matrix. The size parameter is the number of 4x4 matrices; the fact that you’re calling the Matrix4fv version of the function is how it knows that each matrix is 16 floats.

1 Like

Reading documentation is always helpful here: glProgramUniform - OpenGL 4 Reference Pages

1 Like

thank you . this really help!!!

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.