本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Renderer.CreateTexture方法的典型用法代码示例。如果您正苦于以下问题:Golang Renderer.CreateTexture方法的具体用法?Golang Renderer.CreateTexture怎么用?Golang Renderer.CreateTexture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/veandco/go-sdl2/sdl.Renderer
的用法示例。
在下文中一共展示了Renderer.CreateTexture方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Bake
func (gb *GUIBlock) Bake(renderer *sdl.Renderer) *sdl.Texture {
finalTxtr, _ := renderer.CreateTexture(sdl.PIXELFORMAT_RGBA8888, sdl.TEXTUREACCESS_TARGET, 800, 600)
originalTarget := renderer.GetRenderTarget()
renderer.SetRenderTarget(finalTxtr)
defer renderer.SetRenderTarget(originalTarget)
renderer.SetDrawColor(1, 1, 1, 0)
renderer.FillRect(gb.Pos)
for _, el := range gb.Elements {
println("Baking: ")
println(el.Layer, el.Pos.X, el.Pos.Y)
renderer.SetDrawColor(el.BGColor.R, el.BGColor.G, el.BGColor.B, el.BGColor.A)
renderer.FillRect(el.Pos)
for _, txt := range el.Texts {
texture, W, H := txt.Bake(renderer)
renderer.Copy(
texture,
&sdl.Rect{0, 0, W, H},
&sdl.Rect{el.Pos.X + txt.RelPos.X, el.Pos.Y + txt.RelPos.Y, W, H})
}
}
finalTxtr.SetBlendMode(sdl.BLENDMODE_BLEND)
finalTxtr.SetAlphaMod(216)
return finalTxtr
}
示例2: play
func play(seq *video.VideoSequence) {
var window *sdl.Window
var renderer *sdl.Renderer
var texture *sdl.Texture
var err error
window, err = sdl.CreateWindow(winTitle,
sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
winWidth, winHeight,
sdl.WINDOW_SHOWN)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", err)
os.Exit(1)
}
defer window.Destroy()
renderer, err = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", err)
os.Exit(2)
}
defer renderer.Destroy()
seq.AlignTo(video.SequenceHeaderStartCode)
var pointer unsafe.Pointer
var pitch int
var yLen int
var cLen int
sdl.Delay(1000)
renderer.Present()
for {
img, err := seq.Next()
if err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "Decoding error: %s\n", err)
os.Exit(3)
}
if texture == nil {
w, h := seq.Size()
yLen = w * h
cLen = (w * h) >> 2
texture, err = renderer.CreateTexture(sdl.PIXELFORMAT_IYUV, sdl.TEXTUREACCESS_STREAMING, w, h)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", err)
os.Exit(4)
}
defer texture.Destroy()
}
{
texture.Lock(nil, &pointer, &pitch)
// Convert pointer to []uint8
pixels := *(*[]uint8)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(pointer),
Len: yLen + 2*cLen,
Cap: yLen + 2*cLen,
}))
// Select color planes
y := pixels[0:yLen]
cb := pixels[yLen : yLen+cLen]
cr := pixels[yLen+cLen : yLen+cLen+cLen]
// Copy image data into texture
copy(y, img.Y)
copy(cb, img.Cb)
copy(cr, img.Cr)
texture.Unlock()
}
err = renderer.Copy(texture, nil, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "Copy failed: %s\n", err)
os.Exit(5)
}
renderer.Present()
}
}