|
2 weeks ago | |
---|---|---|
canvas | 10 months ago | |
event | 2 weeks ago | |
examples | 1 year ago | |
sdl | 2 weeks ago | |
.gitignore | 1 year ago | |
LICENSE.md | 1 year ago | |
README.md | 1 year ago | |
color.go | 6 months ago | |
ellipse.go | 1 year ago | |
functions.go | 1 year ago | |
go.mod | 10 months ago | |
go.sum | 6 months ago | |
image.go | 10 months ago | |
interface.go | 7 months ago | |
point.go | 9 months ago | |
point_test.go | 9 months ago | |
rect_test.go | 1 year ago | |
shapes.go | 1 year ago | |
version.go | 10 months ago |
Render is a graphics rendering library for Go.
It supports SDL2 and HTML Canvas back-ends enabling its use for both desktop applications (Linux, Mac and Windows) and WebAssembly modules for running in the web browser.
Notice: github.com/kirsle/render is a mirror to the upstream repository at git.kirsle.net/go/render. Issues and pull requests will be accepted at GitHub.
package main
import (
"git.kirsle.net/go/render"
"git.kirsle.net/go/render/sdl"
)
func main() {
mw := sdl.New("Hello World", 320, 240)
if err := mw.Setup(); err != nil {
panic(err)
}
// Text that we're gonna draw in the window.
text := render.Text{
Text: "Hello, world!",
Size: 24,
Color: render.SkyBlue,
Shadow: render.Blue,
FontFilename: "DejaVuSans.ttf",
}
// Compute the rendered size of the text.
rect, _ := mw.ComputeTextRect(text)
for {
// Blank the window.
mw.Clear(render.White)
// Poll for events (mouse clicks, keyboard keys, etc.)
ev, err := mw.Poll()
if err != nil {
panic(err)
}
// Escape key closes the window.
if ev.Escape {
mw.Teardown()
break
}
// Get the window size.
w, h := mw.WindowSize()
// Draw the text centered in the window.
mw.DrawText(text, render.NewPoint(
(w/2) - (rect.W/2),
(h/2) - (rect.H/2),
))
mw.Present()
}
}
See the examples/
directory for examples. More will come eventually,
including some WebAssembly examples.
This module was written as part of my drawing-based maze game, code named Project: Doodle. It is currently in alpha status and its API may change and be cleaned up in the future.
This package provides some basic primitive drawing methods which are implemented for SDL2 (desktops) and HTML Canvas (WebAssembly). See the render.Engine interface. The drawing methods supported are:
This package defines a handful of types useful for drawing operations. See the godoc for full details.
The render package includes a few convenience functions for drawing complex shapes.
The generator functions return a channel that yields all of the Points that should be drawn to complete the shape. Example:
var (
A Point = render.NewPoint(10, 10)
B Point = render.NewPoint(15, 20)
)
for pt := range render.IterLine(A, B) {
engine.DrawPoint(render.Red, pt)
}
MIT.