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


Golang sdl.Renderer類代碼示例

本文整理匯總了Golang中github.com/veandco/go-sdl2/sdl.Renderer的典型用法代碼示例。如果您正苦於以下問題:Golang Renderer類的具體用法?Golang Renderer怎麽用?Golang Renderer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Renderer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SetDrawColor

func SetDrawColor(r *sdl.Renderer, color [4]uint8) {
	r.SetDrawColor(
		color[0],
		color[1],
		color[2],
		color[3])
}
開發者ID:jbott,項目名稱:go-mission-control,代碼行數:7,代碼來源:missioncontrol.go

示例2: 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

示例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: main

func main() {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var event sdl.Event
	var running bool

	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)
	}

	var peepArray []sdl.Event = make([]sdl.Event, 5)

	running = true
	for running {
		sdl.PumpEvents()
		numEventsRetrieved := sdl.PeepEvents(peepArray, sdl.PEEKEVENT, sdl.FIRSTEVENT, sdl.LASTEVENT)
		if numEventsRetrieved < 0 {
			fmt.Printf("PeepEvents error: %s\n", sdl.GetError())
		} else {
			for i := 0; i < numEventsRetrieved; i++ {
				fmt.Printf("Event Peeked Value: %v\n", peepArray[i]) // primitive printing of event
			}
		}

		for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch t := event.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.MouseMotionEvent:
				fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
			case *sdl.MouseButtonEvent:
				fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
			case *sdl.MouseWheelEvent:
				fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y)
			case *sdl.KeyUpEvent:
				fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
					t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
			}
		}
		sdl.Delay(1000 / 30)
	}

	renderer.Destroy()
	window.Destroy()
}
開發者ID:emlai,項目名稱:go-sdl2,代碼行數:57,代碼來源:PeepEvents_peek.go

示例5: Draw

func (d *drawable) Draw(r *sdl.Renderer) {
	// Fill
	if d.fill {
		SetDrawColor(r, d.fill_color)
		r.FillRect(&sdl.Rect{d.X, d.Y, d.W, d.H})
	}

	// Draw bounds
	SetDrawColor(r, d.border_color)
	r.DrawRect(&sdl.Rect{d.X, d.Y, d.W, d.H})
}
開發者ID:jbott,項目名稱:go-mission-control,代碼行數:11,代碼來源:drawable.go

示例6: Draw

func (s *AnimatedSprite) Draw(renderer *sdl.Renderer) {
	src_rect := s.Src_rects[s.current_frame]
	dest_rect := &sdl.Rect{
		int32(s.X),
		int32(s.Y),
		src_rect.W,
		src_rect.H,
	}

	renderer.Copy(s.Texture, src_rect, dest_rect)
}
開發者ID:kageurufu,項目名稱:platformr,代碼行數:11,代碼來源:animated_sprite.go

示例7: Draw

func (d *RectDrawer) Draw(r *sdl.Renderer, offsetX, offsetY int32) error {
	if err := r.SetDrawColor(d.r, d.g, d.b, d.a); err != nil {
		return err
	}
	rect := &sdl.Rect{
		X: d.x + offsetX,
		Y: d.y + offsetY,
		W: d.w,
		H: d.h,
	}
	return r.FillRect(rect)
}
開發者ID:Oralordos,項目名稱:Game-Programming-Project,代碼行數:12,代碼來源:drawing.go

示例8: 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

示例9: 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

示例10: Draw

func Draw(r *sdl.Renderer, g *grid.Grid) {
	g.EachRoom(func(room *grid.Room) {
		x := int32(room.X) * pixelSize * roomSize
		y := int32(room.Y) * pixelSize * roomSize
		width := roomSize * pixelSize
		height := roomSize * pixelSize
		rect := &sdl.Rect{x, y, width, height}

		if room.Blocked {
			r.FillRect(rect)
		} else {
			r.DrawRect(rect)
		}
	})
}
開發者ID:paytonrules,項目名稱:pathfinding,代碼行數:15,代碼來源:gameloop.go

示例11: DrawPath

func DrawPath(r *sdl.Renderer, nodes []graph.Node) {
	for index, node := range nodes {
		if index != 0 {
			previousNode := nodes[index-1]
			startRoom := previousNode.(*grid.Room)
			endRoom := node.(*grid.Room)
			x1 := int32(startRoom.X) * pixelSize * roomSize
			y1 := int32(startRoom.Y) * pixelSize * roomSize
			x2 := int32(endRoom.X) * roomSize * pixelSize
			y2 := int32(endRoom.Y) * roomSize * pixelSize

			r.DrawLine(int(x1), int(y1), int(x2), int(y2))
		}
	}
}
開發者ID:paytonrules,項目名稱:pathfinding,代碼行數:15,代碼來源:gameloop.go

示例12: main

func main() {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var event sdl.Event
	var running bool

	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)
	}

	running = true
	for running {
		event = sdl.WaitEventTimeout(1000) // wait here until an event is in the event queue
		if event == nil {
			fmt.Println("WaitEventTimeout timed out")
			continue
		}

		switch t := event.(type) {
		case *sdl.QuitEvent:
			running = false
		case *sdl.MouseMotionEvent:
			fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
				t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
		case *sdl.MouseButtonEvent:
			fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
				t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
		case *sdl.MouseWheelEvent:
			fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
				t.Timestamp, t.Type, t.Which, t.X, t.Y)
		case *sdl.KeyUpEvent:
			fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
				t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
		}
	}

	renderer.Destroy()
	window.Destroy()
}
開發者ID:emlai,項目名稱:go-sdl2,代碼行數:48,代碼來源:WaitEventTimeout.go

示例13: 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

示例14: run

func run() int {
	var window *sdl.Window
	var renderer *sdl.Renderer
	var event sdl.Event
	var running bool
	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()

	running = true
	for running {
		for event = sdl.PollEvent(); event != nil; event = sdl.PollEvent() {
			switch t := event.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.MouseMotionEvent:
				fmt.Printf("[%d ms] MouseMotion\ttype:%d\tid:%d\tx:%d\ty:%d\txrel:%d\tyrel:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y, t.XRel, t.YRel)
			case *sdl.MouseButtonEvent:
				fmt.Printf("[%d ms] MouseButton\ttype:%d\tid:%d\tx:%d\ty:%d\tbutton:%d\tstate:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y, t.Button, t.State)
			case *sdl.MouseWheelEvent:
				fmt.Printf("[%d ms] MouseWheel\ttype:%d\tid:%d\tx:%d\ty:%d\n",
					t.Timestamp, t.Type, t.Which, t.X, t.Y)
			case *sdl.KeyUpEvent:
				fmt.Printf("[%d ms] Keyboard\ttype:%d\tsym:%c\tmodifiers:%d\tstate:%d\trepeat:%d\n",
					t.Timestamp, t.Type, t.Keysym.Sym, t.Keysym.Mod, t.State, t.Repeat)
			}
		}
	}

	return 0
}
開發者ID:tianon,項目名稱:gb-integration-tests,代碼行數:46,代碼來源:events.go

示例15: 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


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