SFML community forums
Bindings - other languages => DotNet => Topic started by: Metapyziks on January 29, 2011, 04:20:57 pm
-
How would I create a shader instance from a file / from a string in SFML.NET 2.0?
I've tried:
TestShader = new Shader( "Shader.sfx" );
But I get a LoadingFailedException. The file definitely exists at the specified location.
Shader.sfx is just an example shader:
uniform sampler2D tex;
void main()
{
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
}
Loading from a string would be more suitable for my needs, but the LoadFromString() method requires an instance of Shader. I would have expected it to be a static method.
-
But I get a LoadingFailedException. The file definitely exists at the specified location.
Are you sure that your working directory is the one you think it is? When you run the application from the IDE it's often the project directory, not the executable one.
Loading from a string would be more suitable for my needs, but the LoadFromString() method requires an instance of Shader. I would have expected it to be a static method.
You're right, this was a mistake: as Shader doesn't have a default constructor, this function is not usable. I renamed LoadFromString to FromString and made it static :)
-
Thank you for the quick reply!
The file is in the bin\Debug and bin\Release folders with the executable, and is copied there from the project directory on compile (therefore it is in both).
Does the previously mentioned exception occur if the file is found but the contents are bad?
And thanks for changing FromString to be static, I will probably use that instead of from a file.
-
Does the previously mentioned exception occur if the file is found but the contents are bad?
Yes. This is the only exception that is thrown, therefore it gathers all kind of errors that may happen.
-
It may have just been something wrong with the contents then.
Anyway, I got a Shader working through the FromString method. Thanks for your help, and thanks for SFML! :D
-
Another question related to shaders, how would I set the value of an item within an array in the shader?
For example, if I have:
uniform vec2 points[16];
How would I change values in "points" with SFML?
-
I don't know, you have to check this in a GLSL tutorial. Maybe with "points
- " (with x a number) as the key?