Getting an error saying "You need to initialize the OpenGL binding first by calling LoadBindings() or creating a compatible OpenGL window." OpenTK

90 views Asked by At

I was trying to get a start on graphics programming and taking advantage of my familiarity with c#, i used open tk and i was trying to render my first triangle. Shader compiles well at first but after sometime when i tried i get an error on the line where i create shader on the vertex shader handle. ` public Shader(string VertexPath, string FragmentPath) {

        //Handles for individual shaders
        int VertexShaderHandle;
        int FragmentShaderHandle;
        //Reading Shader files
        string VertexShaderSource = File.ReadAllText(VertexPath);
        string FragmentShaderSource = File.ReadAllText(FragmentPath);
        //Creating shaders
        VertexShaderHandle = GL.CreateShader(ShaderType.VertexShader); //the line im getting error
        FragmentShaderHandle = GL.CreateShader(ShaderType.FragmentShader);
        //Settign sources
        GL.ShaderSource(VertexShaderHandle,VertexShaderSource);
        GL.ShaderSource(FragmentShaderHandle,FragmentShaderSource);
        //Compile shaders
        GL.CompileShader(VertexShaderHandle);
        GL.GetShader(VertexShaderHandle, ShaderParameter.CompileStatus, out int success);
        //checking if there are any errors compiling the shaders
        if (success == 0)
        {
            string infoLog = GL.GetShaderInfoLog(VertexShaderHandle);
            Console.WriteLine(infoLog);
        }
        GL.CompileShader(FragmentShaderHandle);
        GL.GetShader(FragmentShaderHandle, ShaderParameter.CompileStatus, out int success1);
        //doing the same
        if (success1 == 0)
        {
            string infoLog = GL.GetShaderInfoLog(FragmentShaderHandle);
            Console.WriteLine(infoLog);
        }
        //Shader Program
        ShaderHandle = GL.CreateProgram();
        GL.AttachShader(ShaderHandle,VertexShaderHandle);
        GL.AttachShader(ShaderHandle,FragmentShaderHandle);
        //Linking
        GL.LinkProgram(ShaderHandle);
        GL.GetProgram(ShaderHandle, GetProgramParameterName.LinkStatus, out int success2);
        //prblem with linking
        if (success2 == 0)
        {
            string infoLog = GL.GetProgramInfoLog(ShaderHandle);
            Console.WriteLine(infoLog);
        }

        //Detaching 
        GL.DetachShader(ShaderHandle,VertexShaderHandle);
        GL.DetachShader(ShaderHandle,FragmentShaderHandle);`

Im sorry i havent used stackoverflow that much so if i did anything wrong or did anything against the rules, please correct me. Thank You.

I tried googling and i couldnt find any solution.

0

There are 0 answers