/
tetris.go
45 lines (38 loc) · 960 Bytes
/
tetris.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/samples/flags"
"os"
"fmt"
"image"
"image/draw"
_ "golang.org/x/image/bmp"
)
func appMain(driver gxui.Driver) {
file := "./img/block.bmp"
f, err := os.Open(file)
if err != nil {
fmt.Printf("Failed to open image '%s': %v\n", file, err)
os.Exit(1)
}
source, _, err := image.Decode(f)
if err != nil {
fmt.Printf("Failed to read image '%s': %v\n", file, err)
os.Exit(1)
}
theme := flags.CreateTheme(driver)
img := theme.CreateImage()
//mx := source.Bounds().Max
window := theme.CreateWindow(1000, 1000, "Tetris")
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(img)
rgba := image.NewRGBA(source.Bounds())
draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src)
texture := driver.CreateTexture(rgba, 1)
img.SetTexture(texture)
window.OnClose(driver.Terminate)
}
func main() {
gl.StartDriver(appMain)
}