Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

WPF/OpenTK. I cannot load shaders from files

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
1 reply to this topic

#1 8Observer8   Members   

159
Like
0Likes
Like

Posted 28 February 2017 - 03:50 AM

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();
            }
        }

Sorry if I make mistakes. My English is not good for a while yet.


#2 8Observer8   Members   

159
Like
0Likes
Like

Posted 28 February 2017 - 06:48 AM

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, 28 February 2017 - 06:53 AM.

Sorry if I make mistakes. My English is not good for a while yet.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.