I have the following GLSL vertex shader code:
#version 330
struct Matrix
{
vec4 row1;
vec4 row2;
vec4 row3;
vec4 row4;
};
uniform Matrix ModelviewProjection;
in vec3 in_Position;
in vec3 in_Color;
out vec3 ex_Color;
void main(void)
{
//gl_Position = vec4(in_Position.x, in_Position.y, in_Position.z, 1.0);
vec4 Position = vec4(in_Position.x, in_Position.y, in_Position.z, 1.0);
vec4 x,y,z,w;
x = ModelviewProjection.row1*Position;
y = ModelviewProjection.row2*Position;
z = ModelviewProjection.row3*Position;
gl_Position.x = x.x+x.y+x.z;
gl_Position.y = y.x+y.y+y.z;
gl_Position.z = z.x+z.y+z.z;
gl_Position.w = 1;
ex_Color = in_Color;
}
At first, the uniform is defined as an identity matrix, i.e. gl_Position=in_Position. If I “push” (using my own function) a rotation matrix onto the uniform, the image shown on screen is rotated. However, if I add any translation data, it is ignored.
That is, if I have the uniform at its default identity value and push the following matrix at the Modelview part:
[cos(30),-sin(30),0,1,
sin(30),cos(30),0,0,
0,0,1,0
0,0,0,1]
The end product of ProjectionModelviewRotation=Rotation, since the others are identity matricies.
Now, if I update the uniform to its new value (=Rotation) and redraw the screen, the image appears rotated by 30 degrees, as it should, however, the x-translation is ignored. If instead the matrix is:
[1,0,0,1,
0,1,0,0,
0,0,1,0,
0,0,0,1]
The matrix might as well be an identity, since nothing happens.
Am I doing something wrong?