added an example for software rendering
updated readme
This commit is contained in:
parent
349e01e301
commit
b5212c916a
2 changed files with 46 additions and 1 deletions
|
@ -14,6 +14,8 @@ The OpenGL backend is intended to provide decent performance. Obviously it will
|
|||
|
||||
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
|
||||
|
||||
The sdlcanvas and glfwcanvas subpackages provide a very simple way to get started with just a few lines of code. As the names imply they are based on the SDL library and the GLFW library respectively. They create a window for you and give you a canvas to draw with.
|
||||
|
|
43
examples/software/software.go
Normal file
43
examples/software/software.go
Normal file
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue