SFML community forums

Help => Graphics => Topic started by: battosaijenkins on May 29, 2020, 08:10:31 pm

Title: sfml gradient shaders question
Post by: battosaijenkins on May 29, 2020, 08:10:31 pm
Hello, I posted a question in github SFML Gradient shaders but was told to post here instead. I was wondering if it's possible to pass an sf::Transform into the draw function along with the shader?

For example normal draw I would pass a transform like:

Code: [Select]
window.draw(circle, transform);

but with shaders that 2nd parameter is already taken up like

Code: [Select]
window.draw(circle, &shader);

 and I cant add a third parameter. I read somewhere that I could use

Code: [Select]
shader.setUniform("matrix", sf::Glsl::Mat4(transform));

but I added

Code: [Select]
"uniform mat4 matrix;"

in const char RadialGradient[] but I'm getting Uniform "matrix" not found in shader. Am I doing it wrong, or overdoing it or missing something?
Title: Re: sfml gradient shaders question
Post by: G. on May 29, 2020, 08:56:04 pm
Hey. You can use an sf::RenderStates (https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1RenderStates.php) and pass it to your draw function instead of only the shader.
Title: Re: sfml gradient shaders question
Post by: battosaijenkins on May 30, 2020, 02:22:46 am
So I cant use sf::Transform?
Title: Re: sfml gradient shaders question
Post by: battosaijenkins on May 30, 2020, 03:01:25 am
Oh I see what you mean. You're saying I would use sf::RenderStates state and then use state.transform = transform and also use &shader in state.shader then pass state like window.draw(circle, state);? I think I understand now, thanks.