當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Renderer.CreateTexture方法代碼示例

本文整理匯總了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
}
開發者ID:billyninja,項目名稱:wander,代碼行數:31,代碼來源:gui.go

示例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()
	}
}
開發者ID:32bitkid,項目名稱:gtsp,代碼行數:87,代碼來源:main.go


注:本文中的github.com/veandco/go-sdl2/sdl.Renderer.CreateTexture方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。