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");

//1st
//the "ugly" way 
glUniform3fARB(loc1,lpos[0],lpos[1],lpos[1]);

//2nd 
//the nicest way
glUniform3fvARB(loc1,1,lpos);


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");
//glUniform3fARB(loc1,lpos[0],lpos[1],lpos[1]);
glUniform3fvARB(loc1,1,lpos);

loc2 = glGetUniformLocation(p,"BrickColor");
//glUniform3fARB(loc2,BrickColor[0],BrickColor[1],BrickColor[2]);
glUniform3fvARB(loc2,1,BrickColor);
						
loc3 = glGetUniformLocation(p,"MortarColor");
//glUniform3fARB(loc3,MortarColor[0],MortarColor[1],MortarColor[2]);
glUniform3fvARB(loc3,1,MortarColor);

loc4 = glGetUniformLocation(p,"BrickSize");
//glUniform2fARB(loc4,BrickSize[0],BrickSize[1]);
glUniform2fvARB(loc4,1,BrickSize);

loc5 = glGetUniformLocation(p,"BrickPct");
//glUniform2fARB(loc5,BrickPct[0],BrickPct[1]);
glUniform2fvARB(loc5,1,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?!

Thanks

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:


glUseProgramObjectARB(p);

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:

Cheers

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.