diff --git a/lesson7/sdl/introduction/test10.go b/lesson7/sdl/introduction/test10.go new file mode 100644 index 0000000..105a475 --- /dev/null +++ b/lesson7/sdl/introduction/test10.go @@ -0,0 +1,54 @@ +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 #10", 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{ + X: width/2 - image.W/2, + Y: height/2 - image.H/2, + W: 0, + H: 0, + } + + err = image.Blit(nil, primarySurface, &dstRect) + if err != nil { + panic(err) + } + + window.UpdateSurface() + + sdl.Delay(5000) +}