/
test03.go
61 lines (53 loc) · 1.31 KB
/
test03.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Šedesátá druhá část
// Programovací jazyk Go a 2D grafika – moduly sdl a img
// https://www.root.cz/clanky/programovaci-jazyk-go-a-2d-grafika-moduly-sdl-a-img/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam demonstračních příkladů z šedesáté druhé části:
// https://github.com/tisnik/go-root/blob/master/article_62/README.md
package main
import "github.com/veandco/go-sdl2/sdl"
const (
width = 640
height = 480
)
func main() {
if err := sdl.Init(sdl.INIT_VIDEO); err != nil {
panic(err)
}
defer sdl.Quit()
window, err := sdl.CreateWindow("SDL2 example #3", sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
width, height, sdl.WINDOW_SHOWN)
if err != nil {
panic(err)
}
defer window.Destroy()
primarySurface, err := window.GetSurface()
if err != nil {
panic(err)
}
primarySurface.FillRect(nil, sdl.MapRGB(primarySurface.Format, 192, 255, 192))
sdl.Delay(1000)
const border = 50
var rects = []sdl.Rect{
sdl.Rect{
X: border,
Y: border,
W: width / 2,
H: height / 2,
},
sdl.Rect{
X: width - width/2 - border,
Y: height - height/2 - border,
W: width / 2,
H: height / 2,
},
}
window.UpdateSurfaceRects(rects)
sdl.Delay(5000)
}