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?

genpfault
  • 51,148
  • 11
  • 85
  • 139
cianBuckley
  • 1,264
  • 2
  • 18
  • 25
  • possible duplicate of [GLSL: passing a list of values to fragment shader](http://stackoverflow.com/questions/7954927/glsl-passing-a-list-of-values-to-fragment-shader) – Nicol Bolas Mar 02 '13 at 22:46

1 Answers1

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];
saiy2k
  • 1,852
  • 1
  • 23
  • 42