Let's say I have a simple fragment shader that draws a gradient:
uniform vec2 u_resolution;
void main() {
vec2 st = gl_FragCoord.xy/u_resolution;
gl_FragColor = vec4(st.x,st.y,0.0,1.0);
}
I have a 350x350 window:
sf::RenderWindow window(sf::VideoMode(350, 350), "SFML");
and I want to use the shader on a 100x100 quad:
vaFrag.setPrimitiveType(sf::Quads);
vaFrag.resize(4);
vaFrag[0].position = sf::Vector2f(0, 0);
vaFrag[1].position = sf::Vector2f(100, 0);
vaFrag[2].position = sf::Vector2f(100, 100);
vaFrag[3].position = sf::Vector2f(0, 100);
I pass resolution of the quad (not the window) to the shader:
shader.setUniform("u_resolution", sf::Vector2f(100, 100));
When I draw the vertexarray with the shader, the shader calculates the entire window as the canvas so I only get a 100x100 portion of the whole gradient drawn.
How can I make it so that the entire gradient is drawn only on the vertexarray quad?