title: OpenGL 4 multisampling with FBO - FBO incomplete
body: <p>I'm making 2D games in OpenTK (a C# wrapper for OpenGL 4), and all was well except for jagged edges of polygons and things jumping and stuttering instead of moving smoothly - so I'm trying to add in multisampling to antialias my textures.</p>
  
  <p>My setup has several Cameras which render all their scene objects onto a FrameBufferObject texture (I would like this to be MSAA), which are then all drawn to the screen (no multisampling needed), one on top of the other.</p>
  
  <p>Without multisampling, it worked fine, but now I tried to change all my Texture2D calls to Texture2DMultisample etc but now I get FBO Not Complete errors and it draws wrong. I believe I need to change my shaders too, but I want to solve this first.</p>
  
  <p>The code below references a few classes like Texture that I've made, but I don't think that should impact this, and I don't want to clutter the post - will give mroe details if needed.</p>
  
  <p>I set up the FBO for each camera with:</p>
  
  <pre><code> private void SetUpFBOTex()
      {
          _frameBufferTexture = new Texture(GL.GenTexture(), Window.W, Window.H);
          GL.BindTexture(TextureTarget.Texture2DMultisample, _frameBufferTexture.ID);           
          GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, 0, PixelInternalFormat.Rgba8, Window.W, Window.H, true);
  
          _frameBufferID = GL.GenFramebuffer();
      }
  </code></pre>
  
  <p>and draw with:</p>
  
  <pre><code>public void Render(Matrix4 matrix)
      {
          GL.Enable(EnableCap.Multisample);
          //Bind FBO to be the draw destination and clear it
          GL.BindFramebuffer(FramebufferTarget.Framebuffer, _frameBufferID);
          GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2DMultisample, _frameBufferTexture.ID, 0);
          GL.ClearColor(new Color4(0,0,0,0));
          GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  
          //draw stuff here 
          foreach (Layer l in Layers)
              l.Render(Matrix);
  
  
          GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
  
          //Bind the FBO to be drawn
          _frameBufferTexture.Bind();
  
          //Translate to camera window position
          Matrix4 fbomatrix = matrix * Matrix4.CreateTranslation(_window.x, _window.y, 0) * FBOMatrix;            
  
          //Bind shader 
          shader.Bind(ref fbomatrix, DrawType);
  
          //Some OpenGL setup nonsense, binding vertices and index buffer and telling OpenGL where in the vertex struct things are, pointers &amp;c
          GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
          GL.EnableVertexAttribArray(shader.LocationPosition);
          GL.VertexAttribPointer(shader.LocationPosition, 2, VertexAttribPointerType.Float, false, Stride, 0);
          if (shader.LocationTexture != -1)
          {
              GL.EnableVertexAttribArray(shader.LocationTexture);
              GL.VertexAttribPointer(shader.LocationTexture, 2, VertexAttribPointerType.Float, false, Stride, 8);
          }
          GL.EnableVertexAttribArray(shader.LocationColour);
          GL.VertexAttribPointer(shader.LocationColour, 4, VertexAttribPointerType.UnsignedByte, true, Stride, 16);
          GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
  
          //Draw the damn quad
          GL.DrawArrays(DrawType, 0, Vertices.Length);
  
          //Cleanup
          GL.DisableVertexAttribArray(shader.LocationPosition);
          if (shader.LocationTexture != -1)
              GL.DisableVertexAttribArray(shader.LocationTexture);
          GL.DisableVertexAttribArray(shader.LocationColour);
      }
  </code></pre>