I have a uniform in a shader like this:
uniform vec3 origins[10];
and a std::vector in my code like this:
std::vector<glm::vec3> origins;
that is filled with ten glm::vec3
elements.
Does anyone know how do I pass that to the shader? I thought:
GLint originsLoc = glGetUniformLocation(programID, "origins");
glUniform3fv(originsLoc, 10, origins.data());
would do it, but it wont compile. The error says there is no matching function for call to 'glUniform3fv'
. How do I pass the data in the std::vector
in a way that satisfies the glUniform3fv
function?
You should use a GLfloat
and not a glm::vec3
, but here it is anyway:
for (int i = 0; i != 10; i++) {
GLint originsLoc = glGetUniformLocation(programID, "origins[i]");
glUniform3f(originsLoc, origins[i].x, origins[i].y, origins[i].z);
}