Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How do you make fragment shaders use a vertexarray as a canvas?  (Read 1298 times)

0 Members and 1 Guest are viewing this topic.

NGM88

  • Full Member
  • ***
  • Posts: 162
    • View Profile
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?

 

anything