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

Author Topic: [SOLVED] How to pass Vec4 to sf::Shader  (Read 2399 times)

0 Members and 1 Guest are viewing this topic.

Drakmyth

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
[SOLVED] How to pass Vec4 to sf::Shader
« on: September 22, 2016, 08:00:27 pm »
tl;dr - I think I found a bug in the new Shader API.



Hi all,

I'm having a little trouble passing a Vec4 color into my shader using the new shader API on 2.4. The documentation suggests that a sf::Color can be converted to a sf::Glsl::Vec4 to be passed into the setUniform method, but I can't get that to happen.

I define my color:
const sf::Color outlineColor = sf::Color::Red;

And then I try the following, which result in the following errors:

shader.setUniform("outlineColor", outlineColor);
Parameter type mismatch: Types 'float' and 'const sf::Color' are not compatible

shader.setUniform("outlineColor", sf::Glsl::Vec4(outlineColor));
Too many arguments, expected 0

I've also tried setting it to a variable first:
sf::Glsl::Vec4 color = outlineColor;
Class 'const sf::Color' is not compatible with class 'sf::Glsl::Vec4'

Thinking maybe it was because my color was const, I tried removing that to no effect. I tried passing a reference:

shader.setUniform("outlineColor", &outlineColor);
But then I get a warning saying: "Parameter type mismatch: Taking boolean from pointer 'sf::Color *' without a cast"

Yet the documentation for setUniform clearly states this should work:
Quote
/// This overload can also be called with sf::Color objects
/// that are converted to sf::Glsl::Vec4.

The documentation for Vec4 even says it:
Quote
/// sf::Glsl::Vec4 vector(1.f, 2.f, 3.f, 4.f);
/// sf::Glsl::Vec4 color = sf::Color::Cyan;
But having tried both of those, I get errors.

This being my first venture into C++ in many years (I work mostly in C# and Java these days), maybe I'm just missing something. Is there some other way I should be going about causing this conversion, or is this a bug in the new Shader API? I wanted to ask here first before creating an issue on GitHub just in case I'm missing some really obvious step. For now I've resorted to calling the old setParameter method which takes an sf::Color directly, but that causes big ugly errors in my output (rightly so, it's deprecated).

Thanks for the help.
« Last Edit: September 22, 2016, 10:18:21 pm by Drakmyth »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to pass Vec4 to sf::Shader
« Reply #1 on: September 22, 2016, 09:21:59 pm »
This compiles for me:

sf::Color color;
shader.setUniform("blop", sf::Glsl::Vec4(color));

Can you please post the exact error message that you get with this code?
Laurent Gomila - SFML developer

Drakmyth

  • Newbie
  • *
  • Posts: 7
    • View Profile
    • Email
Re: How to pass Vec4 to sf::Shader
« Reply #2 on: September 22, 2016, 09:32:13 pm »
Hmm... interesting. It seems to be an IDE error. I am using CLion 2016.2.2, and with that exact line it highlights

sf::Glsl::Vec4(color)
with the error "Too many arguments, expected 0".

But if I hit build anyway (which I hadn't before, because it said there was an error), it compiles and runs just fine. I guess I'll go file a bug report on their side then.

Thanks again.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: How to pass Vec4 to sf::Shader
« Reply #3 on: September 22, 2016, 09:53:05 pm »
So much time wasted because of IDEs trying to be smart, and people blindly trusting them. Just compile, and see what the compiler has to say about your code.
« Last Edit: September 22, 2016, 09:54:41 pm by Laurent »
Laurent Gomila - SFML developer

 

anything