OpenTk - How to Enable Multisampling

874 views Asked by At

I'm trying to implement multisampling in OpenTK but when i enable it there's no diffrence between no antyaliasing and multisampling.

No Antyaliasing

No Antyaliasing

Multisampling Enabled

Multisampling Enabled

Here's a code in OnRenderFrame for multisampling :

protected override void OnRenderFrame(FrameEventArgs e)
    {
        base.OnRenderFrame(e);
        GL.Viewport(0, 0, Width, Height);
        GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        GL.Enable(EnableCap.DepthTest);

        GL.Clear(ClearBufferMask.AccumBufferBit);

        shaders[activeShader].EnableVertexAttribArrays();

        int indiceat = 0;
        GL.Enable(EnableCap.Multisample);
        GL.Hint(HintTarget.MultisampleFilterHintNv,HintMode.Nicest);
        foreach (Volume v in objects)
        {
            GL.ActiveTexture(TextureUnit.Texture0);
            GL.BindTexture(TextureTarget.Texture2D, v.TextureID);
            GL.UniformMatrix4(shaders[activeShader].GetUniform("modelview"), false, ref v.ModelViewProjectionMatrix);

            GL.DrawElements(BeginMode.Triangles, v.IndiceCount, DrawElementsType.UnsignedInt, indiceat * sizeof(uint));
            indiceat += v.IndiceCount;
        }
}
1

There are 1 answers

2
Rabbid76 On BEST ANSWER

You've to create a window with a multisample buffer, by setting the GraphicsMode. Set the GraphicsMode when the GameWindow is constructed:

e.g.:

public class OpenTK_Window
    : GameWindow
{
    OpenTK_Window(int width, int height, string title)
        : base(width, height, new GraphicsMode(32, 24, 8, 8), title,
    {}

    // [...]
}

In this case the 4th parameter to the constructor of GraphicsMode is the number of samples.