-
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
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
-
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 (http://www.sfml-dev.org/documentation/2.3/classsf_1_1Shader.php)?
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.
-
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:
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...
-
iResolution being 800x600 is clearly wrong (and why declared as a vec3?), given that you use it as normalized coordinates in the shader.
-
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().
-
...
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 (https://www.shadertoy.com/new) 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)?!
-
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.
-
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