diff --git a/ext/atlas/README.md b/ext/atlas/README.md new file mode 100644 index 0000000..67785f0 --- /dev/null +++ b/ext/atlas/README.md @@ -0,0 +1,3 @@ +# Atlas Extension + +This is a simple example of the texture atlas extension. diff --git a/ext/atlas/hiking.png b/ext/atlas/hiking.png new file mode 100644 index 0000000..83496bc Binary files /dev/null and b/ext/atlas/hiking.png differ diff --git a/ext/atlas/main.go b/ext/atlas/main.go new file mode 100644 index 0000000..7e49022 --- /dev/null +++ b/ext/atlas/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "github.com/gopxl/pixel/v2" + "github.com/gopxl/pixel/v2/backends/opengl" + "github.com/gopxl/pixel/v2/ext/atlas" + "golang.org/x/image/colornames" +) + +var ( + Atlas atlas.Atlas + group = Atlas.MakeGroup() + hiking = group.AddFile("hiking.png") + gopher = Atlas.AddFile("thegopherproject.png") +) + +func run() { + cfg := opengl.WindowConfig{ + Title: "Atlas example", + Bounds: pixel.R(0, 0, 1024, 768), + } + win, err := opengl.NewWindow(cfg) + if err != nil { + panic(err) + } + defer win.Destroy() + + Atlas.Pack() + + for !win.Closed() { + if win.JustPressed(pixel.KeyEscape) { + win.SetClosed(true) + } + + win.Clear(colornames.Skyblue) + + hiking.Draw(win, pixel.IM.Moved(win.Bounds().Center())) + gopher.Draw(win, pixel.IM.Moved(win.Bounds().Center())) + + win.Update() + } +} + +func main() { + opengl.Run(run) +} diff --git a/ext/atlas/thegopherproject.png b/ext/atlas/thegopherproject.png new file mode 100644 index 0000000..5ffee86 Binary files /dev/null and b/ext/atlas/thegopherproject.png differ