title: Simple OpenTK Shader not working
body: <p>I'm currently trying to get into GLSL using the OpenGL superbible and <a href="http://www.learnopengl.com/" rel="nofollow noreferrer">http://www.learnopengl.com/</a>. My desired environment is OpenTK.</p>
  
  <p>I tried to convert the "<a href="http://www.learnopengl.com/#!Getting-started/Hello-Triangle" rel="nofollow noreferrer">Hello Triangle</a>" entry level tutorial from learnopengl.com into OpenTK, it is meant to draw a triangle using very simple shaders, without using any perspective/world/model transformations.</p>
  
  <p>My result is just the colorbuffer, but else an empty window and i simply do not understand where i have made a mistake so any help in finding and more importantly understanding them would be very appreciated.</p>
  
  <p>My OpenTK code:</p>
  
  <pre><code>using System;
  using System.Drawing;
  using System.Drawing.Imaging;
  using System.IO;
  using OpenTK;
  using OpenTK.Graphics.OpenGL;
  using OpenTK.Input;
  
  namespace learnopengl.HelloTriangle
  {
      public class MainWindow : GameWindow
      {
          int _shaderId;
          int _vao;
          int _glbuf;
          int _fragObj;
          int _vertexObj;
          Vector3[] _triangleVert;
  
          public MainWindow()
              : base(800,600)
          {
              KeyDown += MainWindow_KeyDown;
              _triangleVert = new Vector3[] { 
                  new Vector3(-0.5f, -0.5f, 0.0f),
                  new Vector3(0.5f, -0.5f, 0.0f),
                  new Vector3(-0.5f, 0.5f, 0.0f)
              };
  
          }
  
          void MainWindow_KeyDown(object sender, KeyboardKeyEventArgs e)
          {
              if (e.Key == Key.Escape)
                  this.Exit();
  
              if (e.Key == Key.F11)
                  if (this.WindowState == WindowState.Fullscreen)
                      this.WindowState = WindowState.Normal;
                  else
                      this.WindowState = WindowState.Fullscreen;
          }
  
          protected override void OnLoad(EventArgs e)
          {
              base.OnLoad(e);
              System.Diagnostics.Trace.WriteLine(string.Format("OpenGL version: {0}", GL.GetString(StringName.Version)));
              GL.ClearColor(Color.Purple);
  
              _vertexObj = GL.CreateShader(ShaderType.VertexShader);
              _fragObj = GL.CreateShader(ShaderType.FragmentShader);
              int statusCode;
              string info;
  
              GL.ShaderSource(_vertexObj, File.ReadAllText(@"shader\triangle.vert"));
              GL.CompileShader(_vertexObj);
              info = GL.GetShaderInfoLog(_vertexObj);
              Console.Write(string.Format("triangle.vert compile: {0}",info));
              GL.GetShader(_vertexObj, ShaderParameter.CompileStatus, out statusCode);
              if (statusCode != 1) throw new ApplicationException(info);
  
              GL.ShaderSource(_fragObj, File.ReadAllText(@"shader\triangle.frag"));
              GL.CompileShader(_fragObj);
              info = GL.GetShaderInfoLog(_fragObj);
              Console.Write(string.Format("triangle.frag compile: {0}", info));
              GL.GetShader(_fragObj, ShaderParameter.CompileStatus, out statusCode);
              if (statusCode != 1) throw new ApplicationException(info);
  
              _shaderId = GL.CreateProgram();
              GL.AttachShader(_shaderId, _fragObj);
              GL.AttachShader(_shaderId, _vertexObj);
              GL.LinkProgram(_shaderId);
              Console.Write(string.Format("link program: {0}", GL.GetProgramInfoLog(_shaderId)));
              GL.UseProgram(_shaderId);
              Console.Write(string.Format("use program: {0}", GL.GetProgramInfoLog(_shaderId)));
  
              _vao = GL.GenVertexArray();
              _glbuf = GL.GenBuffer();
              GL.BindVertexArray(_vao);
              GL.BindBuffer(BufferTarget.ArrayBuffer, _glbuf);
              GL.BufferData&lt;Vector3&gt;(BufferTarget.ArrayBuffer, new IntPtr(Vector3.SizeInBytes * _triangleVert.Length), _triangleVert, BufferUsageHint.StaticDraw);
              GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes * _triangleVert.Length, 0);
              GL.EnableVertexAttribArray(0);
              GL.BindVertexArray(0);
          }
  
          protected override void OnResize(EventArgs e)
          {
              GL.Viewport(0, 0, Width, Height);
          }
  
          protected override void OnRenderFrame(FrameEventArgs e)
          {
              GL.Clear(ClearBufferMask.ColorBufferBit);
  
              GL.BindVertexArray(_vao);
              GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
              GL.BindVertexArray(0);
  
              this.SwapBuffers();
          }
  
          protected override void OnUnload(EventArgs e)
          {
              GL.DeleteProgram(_shaderId);
              GL.DeleteShader(_vertexObj);
              GL.DeleteShader(_fragObj);
              GL.DeleteVertexArray(_vao);
              GL.DeleteBuffer(_glbuf);
              base.OnClosed(e);
          }
      }
  }
  </code></pre>
  
  <p>triangle.vert:</p>
  
  <pre><code>#version 330 core
  
  layout(location = 0) in vec3 position;
  
  void main()
  {
      gl_Position = vec4(position.x, position.y, position.z, 1.0f);
  }
  </code></pre>
  
  <p>triangle.frag:</p>
  
  <pre><code>#version 330 core
  
  //out vec4 color;
  
  void main()
  {
      gl_FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
      //color = vec4(1.0f, 0.0f, 0.0f, 1.0f);
  }
  </code></pre>
  
  <p>My Result:
  <a href="https://i.stack.imgur.com/iSgMe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iSgMe.png" alt="enter image description here"></a></p>
  
  <p>Edit:
  Updated the code with the suggestions from the comments, which don't change the outcome.</p>
  
  <p>Also verified that the vbo is filled correctly with gDEBugger:
  <a href="https://i.stack.imgur.com/Xfy0z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Xfy0z.png" alt="enter image description here"></a></p>
  
  <p>Edit2:
  I added the Info log from linking/using the shaders and reroutet all info log to the console. I get some warnings which can be ignored.</p>
  
  <p><a href="https://i.stack.imgur.com/AGomZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AGomZ.png" alt="enter image description here"></a></p>
  
  <p>I also tested if any changes occur if i remove the float suffix from all shaders, but everything stayed the same. </p>