I have a weird problem with glUniform2fv. I use it to update a variable "uniform vec2 name[3];" in my fragment shader. The only thing, is that only the x value of each vec2 is replaces, the y doesn't work. Here's the piece of code updating it:
static float DATA_POINTS[6] = {0.1, 0.1, 0.5, 0.5, 0.8, 0.7};
static float sec_speed[3] = {0.5f, 1.0f, 1.5f};
void updateData(float time)
{
for (int i = 0, j = 0; i < 6; i += 2, ++j)
{
float t = DATA_POINTS + time * sec_speed[j];
if (t > 1.0f)
t -= 1.0f;
DATA_POINTS = t;
}
glUniform2fv(uni_pt, 3, (float*)&DATA_POINTS);
}
this one works perfectly... but when I change it to DATA_POINTS[i + 1], to get my y coordinate in both places, the values are not updated at all. What am I missing here ?
You don't need to take the address of DATA_POINTS (&DATA_POINTS) it is already a pointer to the start of the array. Try this:
glUniform2fv(uni_pt, 3, (GLfloat*)DATA_POINTS);
I think what is probably happening is that DATA_POINTS (the pointer) happens to be followed by zeros in memory. The pointer is also 32bits, which happens to be the same size as GLfloat.
I replace the part of the code with your suggestion and it doesn't work. Actually, it still work for DATA_POINTS, the result is the same, but not for DATA_POINTS[i+1].
Sorry can't see the problem. You are using array initialization in the shader which is a nVidia extension as far as I know. I can't arrays to work AT ALL on ATI. My programs will build but program validation fails. Try doing glValidateProgram, remember to get the program log results. Also try using gDEbugger see if it shows up any errors.
How exactly are you testing the values in the shader? You have a random equation of variables that output some color. How do you conclude that it is just the y values? Can you just output:
glFragColor(pt[n], pt[n],pt[n], 1.0);
Where you recompile for n = 0 through 6 and manually verify. I just don't see in that code how well your getting any feedback of whats in the arrays.
How exactly are you testing the values in the shader? You have a random equation of variables that output some color. How do you conclude that it is just the y values? Can you just output:
glFragColor(pt[n], pt[n],pt[n], 1.0);
Where you recompile for n = 0 through 6 and manually verify. I just don't see in that code how well your getting any feedback of whats in the arrays.
Okay... so the problem is not that the information with glUniform is not transfered. I tried your suggestion, and for each of them, the new value was there.
Sorry can't see the problem. You are using array initialization in the shader which is a nVidia extension as far as I know. I can't arrays to work AT ALL on ATI. My programs will build but program validation fails. Try doing glValidateProgram, remember to get the program log results. Also try using gDEbugger see if it shows up any errors.
It was probably introduced in one of the GLSL versions. I'm too lazy to look it up now.
Also, it is a good idea to declare the #version at the top of the shader otherwise you migt get GLSL 1.10
Sig: http://glhlib.sourceforge.net an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
It was probably introduced in one of the GLSL versions. I'm too lazy to look it up now.
Also, it is a good idea to declare the #version at the top of the shader otherwise you migt get GLSL 1.10
Yeah I specify #version 330 in my shaders and they still refuse to validate with arrays in them. The nVidia OpenGL SDK examples that use arrays also fail to work (although they use uniform initialization in the shader code itself). Latest ATI drivers and everything..