本文整理匯總了Golang中github.com/veandco/go-sdl2/sdl.Surface.Blit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Surface.Blit方法的具體用法?Golang Surface.Blit怎麽用?Golang Surface.Blit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/veandco/go-sdl2/sdl.Surface
的用法示例。
在下文中一共展示了Surface.Blit方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: run
func run() int {
var window *sdl.Window
var font *ttf.Font
var surface *sdl.Surface
var solid *sdl.Surface
var err error
sdl.Init(sdl.INIT_VIDEO)
if err := ttf.Init(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize TTF: %s\n", err)
return 1
}
if window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_SHOWN); err != nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", err)
return 2
}
defer window.Destroy()
if font, err = ttf.OpenFont("../../assets/test.ttf", 32); err != nil {
fmt.Fprint(os.Stderr, "Failed to open font: %s\n", err)
return 4
}
defer font.Close()
if solid, err = font.RenderUTF8_Solid("Hello, World!", sdl.Color{255, 0, 0, 255}); err != nil {
fmt.Fprint(os.Stderr, "Failed to render text: %s\n", err)
return 5
}
defer solid.Free()
if surface, err = window.GetSurface(); err != nil {
fmt.Fprint(os.Stderr, "Failed to get window surface: %s\n", err)
return 6
}
if err = solid.Blit(nil, surface, nil); err != nil {
fmt.Fprint(os.Stderr, "Failed to put text on window surface: %s\n", err)
return 7
}
// Show the pixels for a while
window.UpdateSurface()
sdl.Delay(3000)
return 0
}