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

Author Topic: [SOLVED] sf:Glsel::Vec2 won't compile  (Read 4003 times)

0 Members and 1 Guest are viewing this topic.

AncientGrief

  • Newbie
  • *
  • Posts: 32
    • Yahoo Instant Messenger - what?
    • View Profile
[SOLVED] sf:Glsel::Vec2 won't compile
« on: February 20, 2016, 12:24:32 am »
Hi,

I am trying to learn GLSL with SFML, but this line won't compile:

shader.setUniform(sf::Glsl::Vec2(800.0f,600.0f));
 

What am I missing?!

This is the error I get form MinGW on Windows 10
Code: [Select]
main.cpp:22:52: error: no matching function for call to 'sf::Shader::setUniform(sf::Glsl::Vec2)'

Regards
AncientGrief

P.S. This is the tutorial I am going through:
http://gamedevelopment.tutsplus.com/tutorials/a-beginners-guide-to-coding-graphics-shaders--cms-23313
« Last Edit: February 20, 2016, 02:45:09 pm by AncientGrief »
I grew up with C++...but then I met C#...got lazy...time to turn back to my one and only love!
My system:
Wintendo 10 with Intel i7 4770k
Palit GeForce GTX 980
16 GB RAM

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: sf:Glsel::Vec2 won't compile
« Reply #1 on: February 20, 2016, 12:36:37 am »
Your compiler error is telling you why it won't compile. There is no function called setUniform in sf::Shader. Maybe you are looking for the function setParameter?

Edit: I guess I should add that I'm assuming you are using a released version of SFML. I believe the shader API has changed in the master trunk on github (which does include a setUniform function). If you want to use the new API I believe you need to build SFML from there.
« Last Edit: February 20, 2016, 12:44:50 am by Arcade »

AncientGrief

  • Newbie
  • *
  • Posts: 32
    • Yahoo Instant Messenger - what?
    • View Profile
Re: sf:Glsel::Vec2 won't compile
« Reply #2 on: February 20, 2016, 12:52:32 am »
Thanks for the answer. yes it's the master trunk I am using...

Just reset to 2.3.2 Release (thanks @ IRC @ Eremiell) ... seems to work with setParameter() ...at least it compiles :)

EDIT:
But it still doesn't work ...
My GLSL fragment shader:
Code: [Select]
uniform sampler2D iChannel0;
uniform vec3 iResolution;

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 xy = iResolution.xy;
    xy.y = 1.0 - xy.y;
   
    vec4 texColor = texture2D(iChannel0, xy);
    texColor.b = xy.x;
   
    fragColor = texColor;
}

Edit: But it still does not work:

The shader code:
    text.loadFromFile("texture.png");
    sprite.setTexture(text);
    shader.loadFromFile("shader.frag", sf::Shader::Type::Fragment))

    shader.setParameter("iResolution", 800.0f, 600.0f);
    shader.setParameter("iChannel0",sf::Shader::CurrentTexture);

//....

window.draw(sprite,&shader);
 

Edit2: I just want the texture to be stretched to the window size, like in the tutorial...
« Last Edit: February 20, 2016, 01:13:38 am by AncientGrief »
I grew up with C++...but then I met C#...got lazy...time to turn back to my one and only love!
My system:
Wintendo 10 with Intel i7 4770k
Palit GeForce GTX 980
16 GB RAM

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf:Glsel::Vec2 won't compile
« Reply #3 on: February 20, 2016, 10:34:44 am »
iResolution being 800x600 is clearly wrong (and why declared as a vec3?), given that you use it as normalized coordinates in the shader.
Laurent Gomila - SFML developer

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: sf:Glsel::Vec2 won't compile
« Reply #4 on: February 20, 2016, 11:41:21 am »
I am trying to learn GLSL with SFML, but this line won't compile:

shader.setUniform(sf::Glsl::Vec2(800.0f,600.0f));
 

What am I missing?!
The first parameter -- the uniform name.

Don't use setParameter(), it's deprecated. Upgrade SFML to the latest master if necessary and use setUniform().
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

AncientGrief

  • Newbie
  • *
  • Posts: 32
    • Yahoo Instant Messenger - what?
    • View Profile
Re: sf:Glsel::Vec2 won't compile
« Reply #5 on: February 20, 2016, 12:12:57 pm »
...
What am I missing?!
The first parameter -- the uniform name.

Don't use setParameter(), it's deprecated. Upgrade SFML to the latest master if necessary and use setUniform().

Okay now I feel really stupid ... I shouldn't have coded yesterday ... thank you Nexus

iResolution being 800x600 is clearly wrong (and why declared as a vec3?), given that you use it as normalized coordinates in the shader.

Yes you're right, I orientated the iResolution to Shadertoys variable:
vec3    iResolution     image   The viewport resolution (z is pixel aspect ratio, usually 1.0)

But I figured it out, the shader variable names were wrong:

fragColor must be gl_FragColor

fragCoord.xy must be gl_TexCoord[0].xy
 

What is the best way to stretch the sprite to the window resolution (with shaders)?!
« Last Edit: February 20, 2016, 12:21:54 pm by AncientGrief »
I grew up with C++...but then I met C#...got lazy...time to turn back to my one and only love!
My system:
Wintendo 10 with Intel i7 4770k
Palit GeForce GTX 980
16 GB RAM

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: sf:Glsel::Vec2 won't compile
« Reply #6 on: February 20, 2016, 01:28:45 pm »
Quote
What is the best way to stretch the sprite to the window resolution (with shaders)?!
Not with a fragment shader, which only deals with individual pixels.
Hardly with a vertex shader, which can only handle vertices one by one (you'd have to find a way to tell which corner is each vertex).
Possibly with a geometry shader, but I can't tell more about this subject ;D

The best way is to do it in on C++ side.
Laurent Gomila - SFML developer

AncientGrief

  • Newbie
  • *
  • Posts: 32
    • Yahoo Instant Messenger - what?
    • View Profile
Re: sf:Glsel::Vec2 won't compile
« Reply #7 on: February 20, 2016, 02:44:42 pm »
Quote
What is the best way to stretch the sprite to the window resolution (with shaders)?!
Not with a fragment shader, which only deals with individual pixels.
Hardly with a vertex shader, which can only handle vertices one by one (you'd have to find a way to tell which corner is each vertex).
Possibly with a geometry shader, but I can't tell more about this subject ;D

The best way is to do it in on C++ side.

Thanks Laurent :)

I guess I will stick to SFML's features to achieve this, at least I can now continue to learn GLSL without headaches, I hope  ;D
I grew up with C++...but then I met C#...got lazy...time to turn back to my one and only love!
My system:
Wintendo 10 with Intel i7 4770k
Palit GeForce GTX 980
16 GB RAM

 

anything