/
test11.go
70 lines (57 loc) · 1.45 KB
/
test11.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
62
63
64
65
66
67
68
69
70
// 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/img"
"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 #11", 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)
}
image, err := img.Load("globe.png")
if err != nil {
panic(err)
}
defer image.Free()
primarySurface.FillRect(nil, sdl.MapRGB(primarySurface.Format, 192, 255, 192))
dstRect := sdl.Rect{}
for y := 0; y < 4; y++ {
for x := 0; x < 4; x++ {
image.SetAlphaMod(byte(y*64 + x*16))
dstRect.X = int32(10 + x*100)
dstRect.Y = int32(10 + y*100)
err = image.Blit(nil, primarySurface, &dstRect)
if err != nil {
panic(err)
}
}
}
window.UpdateSurface()
sdl.Delay(5000)
}