Jump to content
  • Advertisement
Sign in to follow this  
8Observer8

WPF/OpenTK. I cannot load shaders from files

This topic is 574 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello,

This version of my program works perfect. It gets shaders from strings:

        string vShaderSource =
            "#version 330\n" +
            "in vec4 a_Position;\n" +
            "void main() {\n" +
            "gl_Position = a_Position;\n" +
            "}\n";
        string fShaderSource =
            "#version 330\n" +
            "out vec4 outColor;\n" +
            "void main() {\n" +
            "outColor = vec4(1.0, 0.0, 0.0, 1.0);\n" +
            "}\n";

Screenshot
Download the Project: Triangle_StringShaders.zip

But when I want to load shaders from files I receive the error, see shreenshot

Download the Project: Triangle_FileShaderError.zip

        string vShaderSource = null;
        string fShaderSource = null;

        // ...

        private void renderCanvas_Load(object sender, EventArgs e)
        {
            // ...

            // Load shaders from files
            LoadShader("./Shaders/vShader.glsl", out vShaderSource);
            LoadShader("./Shaders/fShader.glsl", out fShaderSource);
            if (vShaderSource == null || fShaderSource == null)
            {
                File.AppendAllText(infoFileName, "Failed to load shaders from files");
                return;
            }

            // ...
        }

        private void LoadShader(string fileName, out string shaderSource)
        {
            shaderSource = null;

            using (StreamReader sr = new StreamReader(fileName))
            {
                shaderSource = sr.ReadToEnd();
            }
        }

Share this post


Link to post
Share on other sites
Advertisement

The solution. You need to set for files "vShader.glsl" and "fShader.glsl" in settings: "Copy to Output Directory" to "Copy always".

Edited by 8Observer8

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!