本文整理汇总了Golang中github.com/veandco/go-sdl2/sdl.Renderer类的典型用法代码示例。如果您正苦于以下问题:Golang Renderer类的具体用法?Golang Renderer怎么用?Golang Renderer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Renderer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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] = ¤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}
}
开发者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
示例16: 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
示例17: DrawGraph
func DrawGraph(r *sdl.Renderer, g *graph.Graph) {
nodesDrawn := make(map[graph.Node]struct{})
g.EachAdjacencyList(func(n graph.Node, l []graph.Node) {
for _, d := range l {
_, drawn := nodesDrawn[d]
if !drawn {
startRoom := n.(*grid.Room)
endRoom := d.(*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))
}
}
nodesDrawn[n] = struct{}{}
})
}
开发者ID:paytonrules,项目名称:pathfinding,代码行数:21,代码来源:gameloop.go
示例18: 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
示例19: 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)] = ¤tRect
}
}
return highlightedTexture, notHighlightedTexture, rects, animation.FrameLength
}
开发者ID:ITR13,项目名称:campusFighterI,代码行数:37,代码来源:MenuGenerator.go
示例20: main
func main() {
var window *sdl.Window
var renderer *sdl.Renderer
sdl.Init(sdl.INIT_EVERYTHING)
window = createWindow(winTitle, winHeight, winWidth)
defer window.Destroy()
renderer = createRenderer(window)
defer renderer.Destroy()
var secTickChan = time.Tick(time.Second)
var events = &Events{}
var fps = 0
var view = NewGameView()
for {
// Pump events
events.GetEvents()
// Pass events and renderer to view
view.Render(renderer, events)
// This structure logs the fps
select {
case <-secTickChan:
log.Println("fps:", fps)
fps = 0
default:
fps++
}
// Delay the next frame rendering to free up CPU
sdl.Delay(13)
}
}
开发者ID:Charlesworth,项目名称:goGame,代码行数:37,代码来源:main.go
注:本文中的github.com/veandco/go-sdl2/sdl.Renderer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论