diff --git a/README.md b/README.md index f6b7f89..f8e1b8e 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ The OpenGL backend is intended to provide decent performance. Obviously it will ## Software backend -The software backend can also be used if no OpenGL context is available. It will render into a standard Go RGBA image. +The software backend can also be used if no OpenGL context is available. It will render into a standard Go RGBA image. + +There is experimental MSAA anti-aliasing, but it doesn't fully work properly yet. The best option for anti-aliasing currently is to render to a larger image and then scale it down. ## SDL/GLFW convenience packages diff --git a/examples/software/software.go b/examples/software/software.go new file mode 100644 index 0000000..62b88b8 --- /dev/null +++ b/examples/software/software.go @@ -0,0 +1,43 @@ +package main + +import ( + "image/png" + "math" + "os" + + "github.com/tfriedel6/canvas" + "github.com/tfriedel6/canvas/backend/softwarebackend" +) + +func main() { + backend := softwarebackend.New(720, 720) + cv := canvas.New(backend) + + w, h := float64(cv.Width()), float64(cv.Height()) + cv.SetFillStyle("#000") + cv.FillRect(0, 0, w, h) + + for r := 0.0; r < math.Pi*2; r += math.Pi * 0.1 { + cv.SetFillStyle(int(r*10), int(r*20), int(r*40)) + cv.BeginPath() + cv.MoveTo(w*0.5, h*0.5) + cv.Arc(w*0.5, h*0.5, math.Min(w, h)*0.4, r, r+0.1*math.Pi, false) + cv.ClosePath() + cv.Fill() + } + + cv.SetStrokeStyle("#FFF") + cv.SetLineWidth(10) + cv.BeginPath() + cv.Arc(w*0.5, h*0.5, math.Min(w, h)*0.4, 0, math.Pi*2, false) + cv.Stroke() + + f, err := os.OpenFile("result.png", os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0777) + if err != nil { + panic(err) + } + err = png.Encode(f, backend.Image) + if err != nil { + panic(err) + } +}