Results 1 to 2 of 2

Thread: WPF/OpenTK. I cannot load shaders from files.

  1. #1

    WPF/OpenTK. I cannot load shaders from files.

    Hello,

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

    Code :
            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 Screenshot

    Download the Project: Triangle_FileShaderError.zip

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

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

Similar Threads

  1. Can not load .obj files
    By Otak64 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-26-2018, 07:41 AM
  2. Load TGA files
    By FrznSnake in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-23-2008, 10:21 PM
  3. load dxf files
    By adhara in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-11-2004, 05:27 AM
  4. Load xyz files
    By tyortel in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-06-2004, 08:51 AM
  5. Plib is too big for me, i only want to load 3DS files
    By Morglum in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-08-2001, 11:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean