11package pixelgl
22
33import (
4+ "fmt"
45 "image"
56 "image/color"
67 "runtime"
78
89 "github.com/faiface/glhf"
910 "github.com/faiface/mainthread"
1011 "github.com/faiface/pixel"
12+ "github.com/go-gl/gl/v3.3-core/gl"
1113 "github.com/go-gl/glfw/v3.3/glfw"
1214 "github.com/pkg/errors"
1315)
@@ -75,6 +77,9 @@ type WindowConfig struct {
7577 // Invisible specifies whether the window will be initially hidden.
7678 // You can make the window visible later using Window.Show().
7779 Invisible bool
80+
81+ //SamplesMSAA specifies the level of MSAA to be used. Must be one of 0, 2, 4, 8, 16. 0 to disable.
82+ SamplesMSAA int
7883}
7984
8085// Window is a window handler. Use this type to manipulate a window (input, drawing, etc.).
@@ -119,6 +124,17 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
119124
120125 w := & Window {bounds : cfg .Bounds , cursorVisible : true }
121126
127+ flag := false
128+ for _ , v := range []int {0 , 2 , 4 , 8 , 16 } {
129+ if cfg .SamplesMSAA == v {
130+ flag = true
131+ break
132+ }
133+ }
134+ if ! flag {
135+ return nil , fmt .Errorf ("invalid value '%v' for msaaSamples" , cfg .SamplesMSAA )
136+ }
137+
122138 err := mainthread .CallErr (func () error {
123139 var err error
124140
@@ -134,6 +150,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
134150 glfw .WindowHint (glfw .TransparentFramebuffer , bool2int [cfg .TransparentFramebuffer ])
135151 glfw .WindowHint (glfw .Maximized , bool2int [cfg .Maximized ])
136152 glfw .WindowHint (glfw .Visible , bool2int [! cfg .Invisible ])
153+ glfw .WindowHint (glfw .Samples , cfg .SamplesMSAA )
137154
138155 if cfg .Position .X != 0 || cfg .Position .Y != 0 {
139156 glfw .WindowHint (glfw .Visible , glfw .False )
@@ -163,6 +180,7 @@ func NewWindow(cfg WindowConfig) (*Window, error) {
163180 // enter the OpenGL context
164181 w .begin ()
165182 glhf .Init ()
183+ gl .Enable (gl .MULTISAMPLE )
166184 w .end ()
167185
168186 return nil
0 commit comments