Skip to content

Commit

Permalink
Example #7: blitting via SDL_BlitScaled function
Browse files Browse the repository at this point in the history
  • Loading branch information
tisnik committed May 5, 2020
1 parent 8b303ec commit b8625b6
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions lesson7/sdl/introduction/test07.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 #7", 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)
}

tempImage, err := img.Load("test1.bmp")
if err != nil {
panic(err)
}
defer tempImage.Free()

convertedImage, err := tempImage.Convert(primarySurface.Format, 0)
if err != nil {
panic(err)
}
defer convertedImage.Free()

primarySurface.FillRect(nil, sdl.MapRGB(primarySurface.Format, 192, 255, 192))

err = convertedImage.BlitScaled(nil, primarySurface, nil)
if err != nil {
panic(err)
}

window.UpdateSurface()

sdl.Delay(5000)
}

0 comments on commit b8625b6

Please sign in to comment.