1

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?

6
  • 1
    "it doesnt work"...crash? Nothing drawn? Something unexpected drawn? Commented May 4, 2015 at 20:37
  • It wont compile. Should the code posted compile? The error says there is no matching function for call to 'glUniform3fv'. I edited the question with this info. Commented May 4, 2015 at 20:43
  • 4
    You should have to cast the pointer to a const GLfloat*. Without the cast, the function signature doesn't match. You should also include the *full compiler output. I'm guessing the actual error includes extra type/signature information that you have omitted, unfortunately. Commented May 4, 2015 at 21:05
  • Which version of OpenGL & GLSL are you using? Then if you are using versions 3.2+ then are you using the Core Profile Specification or the Compatibility Profile Specification? Commented May 5, 2015 at 1:56
  • What OS are you using and what IDE - Compiler are you using? Commented May 5, 2015 at 2:02

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answering, that, and @Cornstalks pointed me in the right direction. What I ended up doing is this, which also works: glUniform3fv(originsLoc, origins.size(), reinterpret_cast<GLfloat *>(trackObstacle->obstaclesPopupNormals.data()))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.