SFML community forums

Bindings - other languages => DotNet => Topic started by: Metapyziks on January 29, 2011, 04:20:57 pm

Title: [SFML2] Using Shaders
Post 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:
Code: [Select]
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:
Code: [Select]
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.
Title: [SFML2] Using Shaders
Post by: Laurent on January 29, 2011, 05:37:11 pm
Quote
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.

Quote
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 :)
Title: [SFML2] Using Shaders
Post by: Metapyziks on January 29, 2011, 05:54:29 pm
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.
Title: [SFML2] Using Shaders
Post by: Laurent on January 29, 2011, 06:14:12 pm
Quote
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.
Title: [SFML2] Using Shaders
Post by: Metapyziks on January 29, 2011, 06:35:46 pm
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
Title: [SFML2] Using Shaders
Post by: Metapyziks on January 30, 2011, 03:04:05 pm
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:
Code: [Select]
uniform vec2 points[16];

How would I change values in "points" with SFML?
Title: [SFML2] Using Shaders
Post by: Laurent on January 30, 2011, 05:58:24 pm
I don't know, you have to check this in a GLSL tutorial. Maybe with "points