Any way to enable antialiasing?

Monkey Targets Forums/Desktop/Any way to enable antialiasing?

ziggy(Posted 2014) [#1]
I would love to enable antialiasing on vector drawing commands under GLFW. Any way to do it?


AdamRedwoods(Posted 2014) [#2]
it needs to be requested on window creation for MSAA. or an opengl2.0 shader.


Danilo(Posted 2014) [#3]
Try this with GLFW target, ziggy:
Strict

Import mojo

Extern
    'Function glfwInit:Int()
    Function glfwOpenWindowHint:Void(target:Int, hint:Int)
    Function glfwSetWindowSize:Void(width:Int, height:Int)
    Function glfwSetWindowPos:Void(x:Int, y:Int)
    'Function glfwOpenWindow:Int(width:Int, height:Int, redbits:Int, greenbits:Int, bluebits:Int, alphabits:Int, depthbits:Int, stencilbits:Int, mode:Int )
Public

Const GL_TRUE:Int  = 1
Const GL_FALSE:Int = 0

Const GLFW_STEREO:Int           = $00020011
Const GLFW_WINDOW_NO_RESIZE:Int = $00020012
Const GLFW_FSAA_SAMPLES:Int     = $00020013
Const GLFW_FULLSCREEN:Int       = $00010002

Function RotateAt:Void(x:Float, y:Float, angle:Float)
    Translate(x, y)
    Rotate(angle)
    Translate(-x, -y)
End

Class Program Extends App

    Field angle:Float = 0

    Method OnCreate:Int()
        SetUpdateRate(60)
        
        glfwSetWindowPos(0,0)        ' set window position
        glfwSetWindowSize(1280,1024) ' resize window

        Return 0
    End

    Method OnRender:Int()
        Local dw:Int = DeviceWidth()
        Local dh:Int = DeviceHeight()
        Cls(128,128,128)

        SetColor(0,0,0)
        
        For Local i:Int = 0 To dw Step 20
            DrawLine(0,0,i,dh)
        Next
        
        DrawCircle(dw-100,100,50)
        
        
        'For Local i:Int = 0 To 200 Step 3
        '    RotateAt(dw*0.5,dh*0.5,5)
        '    SetAlpha(255-i)
        '    DrawRect(dw*0.5-200+i,dh*0.5-200+i,400-i*2,400-i*2)
        'Next

        RotateAt(dw*0.5,dh*0.5,angle)
        angle += 0.1
        
        SetColor(0,0,255)
        DrawRect(dw*0.5-100,dh*0.5-100,200,200)
        

        Return 0
    End
    
    Method OnUpdate:Int()
        If KeyHit(KEY_ESCAPE)
            EndApp()
        Endif
        Return 0
    End
End

Function Main:Int()
    
    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 8) ' AntiAliasing samples: 0 = disable AA

    New Program
    Return 0
End

Tested on Mac OS X and Windows with Monkey X 76d, I get nice antialiased lines, circle, rect.
Try with values 4, 8, 16 for AA. 0 to disable (default).


ziggy(Posted 2014) [#4]
Thanks!! That's very appreciated!


Nobuyuki(Posted 2014) [#5]
sweet. +1 danilo


zoqfotpik(Posted 2014) [#6]
One other possibility is rolling it into your line draw routine. There are a number of real fast ways of doing that which aren't much slower than bresenham.