当前位置: 首页>>代码示例>>Golang>>正文


Golang Renderer.CreateTextureFromSurface方法代码示例

本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Renderer.CreateTextureFromSurface方法的典型用法代码示例。如果您正苦于以下问题:Golang Renderer.CreateTextureFromSurface方法的具体用法?Golang Renderer.CreateTextureFromSurface怎么用?Golang Renderer.CreateTextureFromSurface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/veandco/go-sdl2/sdl.Renderer的用法示例。


在下文中一共展示了Renderer.CreateTextureFromSurface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: GenerateMenuShellOneColumn

//TODO Make sdl_tff work!
func (menuGeneratorInfo *MenuGeneratorInfo) GenerateMenuShellOneColumn(renderer *sdl.Renderer, x, y, dx, dy int32) Menu {
	background, err := renderer.CreateTextureFromSurface(menuGeneratorInfo.menuBackground)
	if err != nil {
		panic(err)
	}

	buttonCount := len(menuGeneratorInfo.buttonTexts)

	menuItems := make([]*MenuItem, buttonCount)
	highlightedBackground, notHighlightedBackground, srcRects, FrameLength := menuGeneratorInfo.menuItemAnimation.Generate(renderer)

	TEXTSURFACE := sdl.Texture{}
	TEXTRECT := sdl.Rect{0, 0, 0, 0}

	for i := 0; i < buttonCount; i++ {
		currentRect := sdl.Rect{x, y + dy*int32(i), dx, dy}
		currentRects := make([]*sdl.Rect, len(srcRects))
		for j := 0; j < len(srcRects); j++ {
			currentRects[j] = &currentRect
		}
		previous := (i - 1 + buttonCount) % buttonCount
		next := (i + 1) % buttonCount
		menuAction := MenuAction{nil, func(menuInfo *MenuInfo, menuItem *MenuItem) int { return previous }, func(menuInfo *MenuInfo, menuItem *MenuItem) int { return next }, nil, nil}
		menuItems[i] = &MenuItem{notHighlightedBackground, highlightedBackground, srcRects, currentRects, &TEXTSURFACE, &TEXTRECT, menuAction, FrameLength}
	}
	return Menu{background, menuItems, nil}
}
开发者ID:ITR13,项目名称:campusFighterI,代码行数:28,代码来源:MenuGenerator.go

示例2: DrawItem

func (m *Menu) DrawItem(renderer *sdl.Renderer, index int) {
	var text_surface *sdl.Surface
	var text_texture *sdl.Texture
	var text_width, text_height int32
	var text_rect sdl.Rect
	var screen_width, _, _ int = renderer.GetRendererOutputSize()

	for index, menu_item := range m.menu_items {
		if index == m.selected_item {
			text_surface = m.font.RenderText_Solid(menu_item.text, *m.selected_color)
		} else {
			text_surface = m.font.RenderText_Solid(menu_item.text, *m.unselected_color)
		}
		text_width = text_surface.W
		text_height = text_surface.H

		text_texture = renderer.CreateTextureFromSurface(text_surface)

		text_rect = sdl.Rect{
			int32(screen_width) - 10 - text_width, //X position
			(m.font_size_32 * int32(index)),
			text_width,
			text_height,
		}

		renderer.Copy(text_texture, nil, &text_rect)
	}
}
开发者ID:kageurufu,项目名称:platformr,代码行数:28,代码来源:menu.go

示例3: Bake

func (t *TextEl) Bake(renderer *sdl.Renderer) (*sdl.Texture, int32, int32) {
	surface, _ := t.Font.RenderUTF8_Solid(t.Content, t.Color)
	defer surface.Free()

	txtr, _ := renderer.CreateTextureFromSurface(surface)
	//defer txtr.Destroy()

	return txtr, surface.W, surface.H
}
开发者ID:billyninja,项目名称:wander,代码行数:9,代码来源:gui.go

示例4: LoadTexture

func LoadTexture(renderer *sdl.Renderer, path string) *sdl.Texture {
	bmp, err := img.Load(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to load image %s! SDL Error: %s\n", path, img.GetError())
	} else {
		texture, err := renderer.CreateTextureFromSurface(bmp)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Unable to create texture %s! SDL Error: %s\n", path, sdl.GetError())
		}
		bmp.Free()
		return texture
	}
	return nil
}
开发者ID:EvanTheB,项目名称:SDLGame,代码行数:14,代码来源:graphics.go

示例5: LoadText

func LoadText(renderer *sdl.Renderer, font *ttf.Font, text string, textColor sdl.Color) *sdl.Texture {
	bmp := font.RenderText_Solid(text, textColor)
	if bmp == nil {
		fmt.Fprintf(os.Stderr, "Unable to load text %s! SDL Error: %s\n", ttf.GetError())
	} else {
		texture, err := renderer.CreateTextureFromSurface(bmp)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Unable to create texture %s! SDL Error: %s\n", sdl.GetError())
		}
		bmp.Free()
		return texture
	}
	return nil
}
开发者ID:EvanTheB,项目名称:SDLGame,代码行数:14,代码来源:font.go

示例6: run

func run() int {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var texture *sdl.Texture
	var src, dst sdl.Rect
	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)
		return 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)
		return 2
	}
	defer renderer.Destroy()

	image, err := img.Load(imageName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to load PNG: %s\n", err)
		return 3
	}
	defer image.Free()

	texture, err = renderer.CreateTextureFromSurface(image)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", err)
		return 4
	}
	defer texture.Destroy()

	src = sdl.Rect{0, 0, 512, 512}
	dst = sdl.Rect{100, 50, 512, 512}

	renderer.Clear()
	renderer.SetDrawColor(255, 0, 0, 255)
	renderer.FillRect(&sdl.Rect{0, 0, int32(winWidth), int32(winHeight)})
	renderer.Copy(texture, &src, &dst)
	renderer.Present()

	sdl.Delay(2000)

	return 0
}
开发者ID:emlai,项目名称:go-sdl2,代码行数:49,代码来源:texture_png.go

示例7: main

func main() {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var texture *sdl.Texture
	var src, dst sdl.Rect

	window = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED,
		winWidth, winHeight, sdl.WINDOW_SHOWN)
	if window == nil {
		fmt.Fprintf(os.Stderr, "Failed to create window: %s\n", sdl.GetError())
		os.Exit(1)
	}

	renderer = sdl.CreateRenderer(window, -1, sdl.RENDERER_ACCELERATED)
	if renderer == nil {
		fmt.Fprintf(os.Stderr, "Failed to create renderer: %s\n", sdl.GetError())
		os.Exit(2)
	}

	image := img.Load(imageName)
	if image == nil {
		fmt.Fprintf(os.Stderr, "Failed to load PNG: %s\n", sdl.GetError())
		os.Exit(3)
	}

	texture = renderer.CreateTextureFromSurface(image)
	if texture == nil {
		fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", sdl.GetError())
		os.Exit(4)
	}

	src = sdl.Rect{0, 0, 512, 512}
	dst = sdl.Rect{100, 50, 512, 512}

	renderer.Clear()
	renderer.SetDrawColor(255, 0, 0, 255)
	renderer.FillRect(&sdl.Rect{0, 0, int32(winWidth), int32(winHeight)})
	renderer.Copy(texture, &src, &dst)
	renderer.Present()

	sdl.Delay(2000)

	image.Free()
	texture.Destroy()
	renderer.Destroy()
	window.Destroy()
}
开发者ID:JalfResi,项目名称:go-sdl2,代码行数:47,代码来源:texture_png.go

示例8: main

func main() {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var image *sdl.Surface
	var texture *sdl.Texture
	var src, dst sdl.Rect
	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()

	image, err = sdl.LoadBMP(imageName)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to load BMP: %s\n", err)
		os.Exit(3)
	}
	defer image.Free()

	texture, err = renderer.CreateTextureFromSurface(image)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", err)
		os.Exit(4)
	}
	defer texture.Destroy()

	src = sdl.Rect{0, 0, 512, 512}
	dst = sdl.Rect{100, 50, 512, 512}

	renderer.Clear()
	renderer.Copy(texture, &src, &dst)
	renderer.Present()

	sdl.Delay(2000)
}
开发者ID:flazz,项目名称:go-sdl2,代码行数:46,代码来源:texture.go

示例9: LoadTextureTransparent

func LoadTextureTransparent(renderer *sdl.Renderer, path string, r, g, b uint8) *sdl.Texture {
	bmp, err := img.Load(path)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Unable to load image %s! SDL Error: %s\n", path, img.GetError())
	} else {
		if bmp.SetColorKey(1, sdl.MapRGB(bmp.Format, r, g, b)) != 0 {
			fmt.Fprintf(os.Stderr, "Unable to set Color Key %s! SDL Error: %s\n", path, sdl.GetError())
		}
		texture, err := renderer.CreateTextureFromSurface(bmp)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Unable to create texture %s! SDL Error: %s\n", path, sdl.GetError())
		}
		bmp.Free()
		return texture
	}
	return nil
}
开发者ID:EvanTheB,项目名称:SDLGame,代码行数:17,代码来源:graphics.go

示例10: Load

// Load loads the image into a Texture
func Load(renderer *sdl.Renderer, fileName, id string) error {
	tempSurface, err := img.Load(fileName)

	if err != nil {
		return err
	}

	defer tempSurface.Free()

	texture, err := renderer.CreateTextureFromSurface(tempSurface)

	if err != nil {
		return err
	}

	textureMap[id] = texture

	return nil
}
开发者ID:yukiisbored,项目名称:Kaori,代码行数:20,代码来源:texture.go

示例11: Draw

func (t *Label) Draw(renderer *sdl.Renderer) {
	surface, err := t.font.RenderUTF8_Solid(t.text, sdl.Color{255, 255, 255, 255})
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create surface: %s\n", err)
		os.Exit(1)
	}

	texture, err := renderer.CreateTextureFromSurface(surface)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Failed to create texture: %s\n", err)
		os.Exit(1)
	}

	src := &sdl.Rect{0, 0, surface.W, surface.H}
	dst := &sdl.Rect{t.rect.X, t.rect.Y, src.W, src.H}

	renderer.Copy(texture, src, dst)
	surface.Free()
}
开发者ID:stephenbinns,项目名称:ein,代码行数:19,代码来源:label.go

示例12: DrawTitle

func (m *Menu) DrawTitle(renderer *sdl.Renderer) {
	var text_surface *sdl.Surface
	var text_texture *sdl.Texture
	var text_width, text_height int32
	var title_rect sdl.Rect
	var _, screen_height, _ int = renderer.GetRendererOutputSize()

	text_surface = m.title_font.RenderText_Solid(m.menu_title, *m.title_color)

	text_width = text_surface.W
	text_height = text_surface.H

	text_texture = renderer.CreateTextureFromSurface(text_surface)

	title_rect = sdl.Rect{
		20, //X position
		int32(screen_height) - 20 - text_height, //Y position
		text_width,
		text_height,
	}

	renderer.Copy(text_texture, nil, &title_rect)
}
开发者ID:kageurufu,项目名称:platformr,代码行数:23,代码来源:menu.go

示例13: Generate

func (animation *MenuItemAnimation) Generate(renderer *sdl.Renderer) (*sdl.Texture, *sdl.Texture, []*sdl.Rect, uint64) {
	highlightedTexture, err := renderer.CreateTextureFromSurface(animation.highlightedAnimation)
	if err != nil {
		panic(err)
	}
	notHighlightedTexture, err := renderer.CreateTextureFromSurface(animation.notHighlightedAnimation)
	rows := animation.highlightedAnimation.W / animation.dx
	columns := animation.highlightedAnimation.H / animation.dy
	rects := make([]*sdl.Rect, rows*columns)
	xMult := columns * int32((animation.AnimationDirection>>YX)%2)
	if xMult == 0 {
		xMult = 1
	}
	yMult := rows * int32(1-(animation.AnimationDirection>>YX)%2)
	if yMult == 0 {
		yMult = 1
	}
	xDir := int32(1)
	xPluss := int32(0)
	yDir := int32(1)
	yPluss := int32(0)
	if (animation.AnimationDirection>>LeftRight)%2 == 0 {
		xDir = -1
		xPluss = rows
	}
	if (animation.AnimationDirection>>UpDown)%2 == 0 {
		yDir = -1
		yPluss = columns
	}
	for y := int32(0); y < columns; y++ {
		for x := int32(0); x < rows; x++ {
			currentRect := sdl.Rect{animation.dx * x, animation.dy * y, animation.dx, animation.dy}
			rects[((xPluss+x*xDir)*xMult + (yPluss+y*yDir)*yMult)] = &currentRect
		}
	}
	return highlightedTexture, notHighlightedTexture, rects, animation.FrameLength
}
开发者ID:ITR13,项目名称:campusFighterI,代码行数:37,代码来源:MenuGenerator.go

示例14: Render

func (s *Scene) Render(renderer *sdl.Renderer) {

	// Empty CullM
	s.CullM.Zero()

	var init int32 = 0
	var Source *sdl.Rect

	var ofX, ofY int32 = tileSize, tileSize

	renderer.SetDrawColor(0, 0, 0, 255)

	// Rendering the map
	for sh := init; sh < s.Window.Height; sh += ofY {

		for sw := init; sw < s.Window.Width; sw += ofX {

			ofX = (tileSize - ((s.Cam.WX + sw) % tileSize))
			ofY = (tileSize - ((s.Cam.WY + sh) % tileSize))

			var worldCellX uint16 = uint16((s.Cam.WX + sw) / tileSize)
			var worldCellY uint16 = uint16((s.Cam.WY + sh) / tileSize)

			// Draw black box for out of bounds areas
			if worldCellX < 0 || worldCellX > s.WidthCells || worldCellY < 0 || worldCellY > s.HeightCells {
				renderer.FillRect(&sdl.Rect{sw, sh, ofX, ofY})
				continue
			}

			rect := Object{
				Pos: sdl.Rect{sw, sh, ofX, ofY},
			}

			for _, gfx := range s.World[worldCellX][worldCellY].Gfxs {

				if gfx != nil {

					if gfx.Txtr == nil {
						continue
					}

					if ofX != int32(tileSize) || ofY != int32(tileSize) {
						Source = &sdl.Rect{gfx.Source.X + (tileSize - ofX), gfx.Source.Y + (tileSize - ofY), ofX, ofY}
					} else {
						Source = gfx.Source
					}

					renderer.Copy(s.TsTxt, Source, &rect.Pos)

				}
			}

			// Updating CullM with SOLID/COLLIDABLE terrain types
			if s.World[worldCellX][worldCellY].Coll {

				// fabricate fake SOL obj
				tempO := &Object{
					Pos:  rect.Pos,
					Gfx:  nil,
					Type: SOL,
				}
				s.CullM.Add(tempO, s)
			}
		}
	}

	// Rendering the enemies
	for _, e := range s.Enemies {
		in, e_pos := s.CullM.Add(e, s)
		if in {
			renderer.Copy(s.SsTxt, e.GetPose(), &e_pos)
		}
	}

	// Rendering the player character
	pos := WorldToScreen(s.PC.Pos, s.Cam)
	renderer.Copy(s.SsTxt, s.PC.GetPose(), &pos)

	// Rendering FRAME RATE COUNTER
	fps := fmt.Sprintf("%v", s.GetFPS())
	surface, _ := s.Font.RenderUTF8_Solid(fps, sdl.Color{255, 255, 255, 255})
	defer surface.Free()

	txtr, _ := renderer.CreateTextureFromSurface(surface)
	defer txtr.Destroy()
	renderer.Copy(txtr, &sdl.Rect{0, 0, surface.W, surface.H}, &sdl.Rect{0, 0, surface.W, surface.H})

	// Rendering Game Objects
	for _, obj := range s.Objects {

		in, obj_pos := s.CullM.Add(obj, s)
		if in {
			renderer.SetDrawColor(255, 0, 0, 125)
			renderer.FillRect(&obj_pos)
		}
	}

	// Rendering GUI Blocks
	for _, gb := range s.GUIBlocks {
		renderer.Copy(gb.Baked, gb.Pos, gb.Pos)
//.........这里部分代码省略.........
开发者ID:billyninja,项目名称:wander,代码行数:101,代码来源:scene.go

示例15: WriteOnScreen

func (t *TestState) WriteOnScreen(renderer *sdl.Renderer, text string, X int32, Y int32) {
	text_surface := t.font.RenderText_Solid(text, sdl.Color{255, 255, 255, 255})
	text_texture := renderer.CreateTextureFromSurface(text_surface)
	renderer.Copy(text_texture, nil, &sdl.Rect{X, Y, text_surface.W, text_surface.H})
}
开发者ID:kageurufu,项目名称:platformr,代码行数:5,代码来源:test_state.go


注:本文中的github.com/veandco/go-sdl2/sdl.Renderer.CreateTextureFromSurface方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。