Pass a float array as a uniform value

hello everyone,

i just got the orange yesterday , and has i´m doing the 1st example in chapter6, i have a few problems with the uniform values to pass to either the vertex shader or the frag shader, now has i set up the shader with Shader Designer, it all works fine no problems, but has i try to make an opengl application, passing the uniform values to the shader i get this weired thing in my pattern.

My first thought is that probably i´m not passing the values right to the shaders, i have tried both ways for example, let´s say i have a Color to passand this color is a Color[3], wich means i have 3 float values to pass i can either do one of this 2 options:

//Uniform name in the shader : Color 
loc1 = glGetUniformLocation(p,"Color");

//the "ugly" way 

//the nicest way

on my first way i just pass the values each one at the time,on the second i want to pass the color as a vector,wich seems no me a bit more accurate, as i choose the second aproach to pass uniforms values, crazy or not i get the same error in the shading.

Passing al my uniforms is done like this:

float BrickColor[3] ={1.0,0.3,0.2};
float MortarColor[3]={0.85,0.86,0.84};
float BrickSize[2]={0.3,0.2};
float BrickPct[2]={0.9,0.85};
loc1 = glGetUniformLocation(p,"LightPosicao");

loc2 = glGetUniformLocation(p,"BrickColor");
loc3 = glGetUniformLocation(p,"MortarColor");

loc4 = glGetUniformLocation(p,"BrickSize");

loc5 = glGetUniformLocation(p,"BrickPct");

As you can see i prefer using a glUniform2fv than a glUniform2f and pass evey single value.

Let me show you a picture of the rendering:

any ideias on what´s going on?!


Is your shader program bound when you do the calls to glUniform…() ? Otherwise, I don’t see anything wrong with the sample you provided.

Try passing your uniform values one vec3 at a time to gl_FragColor. This way, you will be able to see if any of them is in error. You can then continue outputing intermediary results to gl_FragColor to find at which point your values are not what you expect them to be.

Yes, as soon as i link and use the program:


right after this i define all my uniform values and pass them to the shaders, i have passed values to the shaders in my other examples, and it works fine,with this one i don´t know what´s going on…i have tired to rewrite the way that i pass the uniforms and i all get to this render above…why? :frowning:

that´s a good ideia pass every single one of then as a color to gl_FragColor and see witch ones are not fine…i´ll have a try at that.

Thanks for your time.

all the arrays vere fine in the shader, the problem was that i was linking more than one program, and when i switch to a diferent one, i wasn´t deleting the previous program well so there was like “conflict” when loading another shader and linking and compile another program, in this case the brick pattern.
Passing the values in both ways were working fine.
Thanks for the tip! :slight_smile: