m34tcode's picture

Anti-Aliasing not working

I copied code directly from the example, and modified only the instantiation of the GameWindow, to add anti-aliasing.

This was the result which compiles but does not anti-alias:

using System;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using OpenTK.Input;
 
namespace Example
{
    class MyApplication
    {
        [STAThread]
        public static void Main()
        {
            using (var game = new GameWindow(400,400,new GraphicsMode(32,24,0,4)))
            {
                game.Load += (sender, e) =>
                {
                    // setup settings, load textures, sounds
                    game.VSync = VSyncMode.On;
                };
 
                game.Resize += (sender, e) =>
                {
                    GL.Viewport(0, 0, game.Width, game.Height);
                };
 
                game.UpdateFrame += (sender, e) =>
                {
                    // add game logic, input handling
                    if (game.Keyboard[Key.Escape])
                    {
                        game.Exit();
                    }
                };
 
                game.RenderFrame += (sender, e) =>
                {
                    // render graphics
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
 
                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();
                    GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);
 
                    GL.Begin(PrimitiveType.Triangles);
 
                    GL.Color3(Color.MidnightBlue);
                    GL.Vertex2(-1.0f, 1.0f);
                    GL.Color3(Color.SpringGreen);
                    GL.Vertex2(0.0f, -1.0f);
                    GL.Color3(Color.Ivory);
 
                    GL.Vertex2(1.0f, 1.0f);
 
                    GL.End();
 
                    game.SwapBuffers();
                };
 
                // Run the game at 60 updates per second
                game.Run(60.0);
            }
        }
    }
}

Result:

Before antialiasing was added it looked like this:

I just modified the fourth parameter in the GameWindow constructor to change the anti-aliasing from 0,2,4, or 8


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

The code looks right, what graphics card and drivers are you using? Edit: am I right to assume you are using OpenTK 1.1?

Try the following to isolate the cause:

  • Make sure your OpenGL drivers are correctly installed. Check the return value of GL.GetString(StringName.Renderer) - it should list the vendor of your graphics card.
  • Check your 3d settings in the control panel of your graphics card and make sure antialiasing is set to "Application controlled".
  • Copy SDL2.dll from opentk/Dependencies/x86 or opentk/Dependencies/x64 to your application directory. This will enable the SDL2 backend which may behave differently. (Conversely, if you are already using the SDL2 backend, remove the dll to test the native win32 backend.)
  • If the above do not help, compile a debug version of OpenTK.dll and post the diagnostic messages from the output window of Visual Studio.

In general, MSAA requires support for WGL_ARB_create_context and WGL_ARB_multisample. If these are missing, OpenTK will fall back to PixelFormatDescriptor, which does not support MSAA. In that case, the debug version of OpenTK.dll will log a diagnostic message to the output window of Visual Studio.

(As general debugging assistance, you can also use apitrace to gather information about the state of OpenGL. This is an invaluable little utility that can save hours of frustration when debugging OpenGL issues.)