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

Author Topic: LoadingFailedException using PostFx object  (Read 6245 times)

0 Members and 1 Guest are viewing this topic.

Martin

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Weaving Stories
LoadingFailedException using PostFx object
« on: July 06, 2010, 12:56:07 pm »
(Apologies if this issue has been brought up in a separate thread. If it has, I've been unable to find it.)

I am using the .NET bindings for SFML 1.6. I have been happily drawing sprites and so forth to the screen using the RenderWindow. I then took a look at the PostFx tutorial.

I copied the GSGL code from the tutorial, and have it in a file whose path is "fx/grey.sfx":

 
Code: [Select]
texture framebuffer
vec3 color

effect
{
    // Get the value of the current screen pixel
    vec4 pixel = framebuffer(_in);

    // Compute its gray level
    float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11;

    // Finally write the output pixel using 50% of the source pixel and 50% of its colored version
    _out = vec4(gray * color, 1.0) * 0.5 + pixel * 0.5;
}


I am able to load this file in as a string using a StreamReader object, so the program definitely has access to it.

However, when I try and construct a PostFx object, passing in that path as the parameter, it throws a LoadingFailedException. This happens with other sfx files I have tried as well. The message in the exception is "Failed to load post-fx from file fx/grey.sfx". Looking at the source code for PostFx, as far as I can tell the .NET bindings always throw away any information the C code might return on why the thing has failed to load and just throw this exception.

The tutorial says that errors during compilation of the fragment shader code will appear on the standard error out. As far as I can work out, this is not the case under C#.NET. If there is a way of getting at that kind of output, please let me know.

Otherwise, any other ideas what I'm doing wrong?

Code: [Select]
using SFML.Graphics;

namespace SFMLTest
{
    class TestMain
    {
        static void Main()
        {
            PostFx fx = null;

            if (PostFx.CanUsePostFX)
            {
                string filename = "fx/grey.sfx";
                fx = new PostFx(filename);
            }
        }
    }
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
LoadingFailedException using PostFx object
« Reply #1 on: July 06, 2010, 02:08:10 pm »
Are you sure that the working directory is the parent of /fx? Do you run your application from the IDE, or from the explorer? Can you load other types of resources (for example images)?
Laurent Gomila - SFML developer

Martin

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Weaving Stories
LoadingFailedException using PostFx object
« Reply #2 on: July 06, 2010, 02:29:08 pm »
Thank you for the reply, Laurent. Let me know if this doesn't provide you with sufficient information:

The fx folder's contents is copied to the working directory at compile time, using Visual Studio's "Copy to Ouptput Directory" option. But in any case, as I mentioned, I can load the files using a FileStream, so that must be a valid path.

I run from the IDE normally, but I have reproduced the bug running from the explorer.

I can load images using the Image object, I haven't tried loading any other resources. If you tell me which resource to try, I'd be happy to.
Edit: I have also successfully loaded a font file.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
LoadingFailedException using PostFx object
« Reply #3 on: July 06, 2010, 02:40:55 pm »
Have you tried the other post-effects provided in the SDK? Have you tried the Post-Fx sample directly?
Laurent Gomila - SFML developer

Martin

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Weaving Stories
LoadingFailedException using PostFx object
« Reply #4 on: July 06, 2010, 05:34:01 pm »
I have now tried the samples from the SDK, including the one the tutorial is based off - and they work fine! Thank you.

Sorry, I should have thought of that.

It turns out it's one of these mysterious bugs - if I copy and paste from the SDK sample into my sfx file so that they're character for character the same, it doesn't work. It's apparently just a cursed file.

But every other file seems to be working fine, so I'll leave it at that. Sorry for using you as tech support!

Martin

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Weaving Stories
LoadingFailedException using PostFx object
« Reply #5 on: July 06, 2010, 05:46:46 pm »
At a guess, it looks like it might be something to do with line endings. The files seem fine until they get saved by Visual Studio.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
LoadingFailedException using PostFx object
« Reply #6 on: July 06, 2010, 06:13:54 pm »
Quote from: "Martin"
At a guess, it looks like it might be something to do with line endings. The files seem fine until they get saved by Visual Studio.

Strange. It shouldn't matter.
Laurent Gomila - SFML developer