1

I'm trying to pass an array to a fragment shader:

//c++ code
float filter[9] = {-1.0f,-1.0f,-1.0f, -1.0f,9.0f,-1.0f, -1.0f,-1.0f,-1.0f};           
glUniform1fv(glGetUniformLocation(imageShaderId, "filter"), 9, filter);


//inside fragment shader code
uniform float filter[9]; //global
if(filter[0]==-1.0) gl_FragColor = red;//in main()

This doesnt work for me.. I've looked at many examples and all seem to point to my code being correct? i can pass a single variable float without issues using glUniform1f, but not the array. Can somebody point me in the right direction?

1

1 Answer 1

3

Here is how I passed a float array to fragment shader:

C++

GLfloat params[3];
params[0] = 2.0f;
params[1] = 1.0f;
params[2] = 1.0f;

colorRampUniformLocation = glGetUniformLocation(glprog->getProgram(), "params");
glUniform1fv(colorRampUniformLocation, 3, params);

In Shader:

uniform float params[3];
Sign up to request clarification or add additional context in comments.

Comments

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.