简体   繁体   English

OpenTk - 如何启用多重采样

[英]OpenTk - How to Enable Multisampling

I'm trying to implement multisampling in OpenTK but when i enable it there's no diffrence between no antyaliasing and multisampling.我正在尝试在 OpenTK 中实现多重采样,但是当我启用它时,没有抗锯齿和多重采样之间没有区别。

No Antyaliasing无抗锯齿

无抗锯齿

Multisampling Enabled启用多重采样

启用多重采样

Here's a code in OnRenderFrame for multisampling:这是 OnRenderFrame 中用于多重采样的代码:

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;
        }
}

You've to create a window with a multisample buffer, by setting the GraphicsMode .您必须通过设置GraphicsMode创建一个带有多重采样缓冲区的窗口。 Set the GraphicsMode when the GameWindow is constructed:在构造GameWindow时设置GraphicsMode

eg:例如:

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.在这种情况下, GraphicsMode构造函数的第 4 个参数是样本数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM