GLSL: troubles with uniform float variables

Hi all!

I’m coding via Debian 6.0.1, C (without C++).
Also I use GLSL shaders. And I have a problem here: all uniform variables with float(vec2, vec3, vec4) types always is zero in my shaders. But “int” and “sampler2D” is ok.

What’s can be wrong there?

Thanks!

Best regards, Serge.

Probably because you didn’t set them correctly. For more elaborated answer more information about the problem is needed.

Ok!
I don’t make any differents between settings the “int” and “float” variables.
So, in the program this:


glUniform1fARB(glGetUniformLocationARB(gv_Shader_Test, "MY_FLOAT_VAR"), 10.0);
glUniform1iARB(glGetUniformLocationARB(gv_Shader_Test, "MY_INT_VAR"), 25);

In the shader it seems like this:


uniform float MY_FLOAT_VAR;
uniform int MY_INT_VAR;

void main(void)
{
  vec3 color = vec3(1.0, 0.5, 0.25);
  gl_FragColor = vec4(color, 1.0);
}

Also I have a script(#1) in my program:


char *s = (char*)malloc(255);
int l = 0;
int i = 0;
for(i = 0; i < 5; i++)
{
  glGetActiveUniformName(gv_Shader_Test, i, 255, &l, s);
  if(s != NULL)
  {
    printf("
l = %i, s = \"%s\"", l, s);
  }
}

When I don’t use the variables in the shader, the script #1 returns:


l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"

Then I apply the changes to the fragment-shader:


void main(void)
{
  vec3 color = vec3(1.0, 0.5, 0.25);
  color /= MY_INT_VAR;

  gl_FragColor = vec4(color, 1.0);
}

The script #1 returns:


l = 10, s = "MY_INT_VAR"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"

That is ok! When I’m setting different values to MY_INT_VAR, I’m getting different colors.

Then I apply another changes to the fragment-shader:


void main(void)
{
  vec3 color = vec3(1.0, 0.5, 0.25);
  color /= MY_FLOAT_VAR;

  gl_FragColor = vec4(color, 1.0);
}

So, I have:


l = 12, s = "MY_FLOAT_VAR"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"
l = 37, s = "gl_ModelViewProjectionMatrixTranspose"

But in the shader MY_FLOAT_VAR is always zero. So, I’m setting different values to MY_FLOAT_VAR, but getting only white color.