我正在尝试使用 golang.org/x/exp/shiny/screen 创建一个窗口,然后在屏幕上绘制一个缓冲区。
我已为窗口和在窗口上发布的缓冲区分配了相同的边界(高度和宽度),但当我看到结果时似乎存在不匹配。
您可以在图片中看到,上传到窗口的蓝色缓冲区并未完全覆盖它。
package main
import (
"image"
"image/color"
"log"
"golang.org/x/exp/shiny/driver"
"golang.org/x/exp/shiny/screen"
"golang.org/x/mobile/event/key"
"golang.org/x/mobile/event/lifecycle"
)
const (
Row = 32
Col = 64
)
// Colors
var (
Black = color.RGBA{0, 0, 0, 1.0}
White = color.RGBA{255, 255, 255, 1.0}
Blue = color.RGBA{0, 0, 255, 1.0}
)
func main() {
go driver.Main(func(s screen.Screen) {
opts := screen.NewWindowOptions{
Height: Row,
Width: Col,
Title: "Chip-8 VM",
}
window, err := s.NewWindow(&opts)
if err != nil {
log.Print("Unable to create display window: ")
log.Fatal(err)
return
}
defer window.Release()
dim := image.Point{Col, Row}
drawBuff, err := s.NewBuffer(dim)
if err != nil {
log.Fatal(err)
}
defaultDrawToBuffer(drawBuff.RGBA())
log.Print("Window bounds: ", opts)
log.Printf("Buffer bounds: %s", drawBuff.Bounds())
log.Printf("Buffer size: %s", drawBuff.Size())
window.Upload(image.Point{}, drawBuff, drawBuff.Bounds())
window.Publish()
for {
e := window.NextEvent()
switch e := e.(type) {
case lifecycle.Event:
if e.To == lifecycle.StageDead {
return
} else if e.To == lifecycle.StageFocused {
log.Print("Focus back on the screen!")
}
case key.Event:
log.Print("pressed key: ", e.Code)
// exit game
if e.Code == key.CodeEscape {
return
}
case error:
log.Print(e)
}
}
})
for {
}
}
临摹微笑
相关分类