本文整理汇总了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])
}
示例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] = ¤tRect
}
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}
}
示例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
}
示例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()
}
示例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})
}
示例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)
}
示例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)
}
示例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
}
示例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
}
示例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)
}
})
}
示例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))
}
}
}
示例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()
}
示例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
}
示例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
}
示例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
}