Hi all,
I have a problem interpolating a value using shaders.
I have the following code:
vertex shader:
varying float value;
void main(){
gl_Position = gl_Vertex;
value = gl_Color.r;
}";
pixel shader:
varying float value;
vec4 color = (0., 0., 0., 0.);
void main(){
gl_FragColor = color;
gl_FragColor.r = value;
}
glcode:
glBegin(GL_QUADS);
glColor3f(0, 0, 0);
glVertex2f(-1, -1); //BL
glColor3f(1, 0, 0);
glVertex2f(-1, 1); //TL
glColor3f(0, 0, 0);
glVertex2f(1, 1); //TR
glColor3f(0, 0, 0);
glVertex2f(1, -1); //BR
glEnd();
It draws a square covering the whole screen.
As you can see, the top left color is red, the rest is black.
The intermediate values are then interpolated using the varying value variable and the result is this:
Now I put the red corner to the top right instead of top left:
glcode:
glBegin(GL_QUADS);
glColor3f(0, 0, 0);
glVertex2f(-1, -1); //BL
glColor3f(0, 0, 0);
glVertex2f(-1, 1); //TL
glColor3f(1, 0, 0);
glVertex2f(1, 1); //TR
glColor3f(0, 0, 0);
glVertex2f(1, -1); //BR
glEnd();
and I get this image:
I expect a rotated but otherwise identical picture, but the results are totally different.
Is it supposed to do that or is it a bug?
How do I get the result I expect?
Any help is appreciated.