Sign in to follow this  
8Observer8

WPF/OpenTK. I cannot load shaders from files

Recommended Posts

8Observer8    160

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this