banana

package module
v0.0.0-...-5202d7a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 10 Imported by: 0

README

banana engine

Go Report Card Go Reference

banana engine is a 2d graphics engine.

currently supported

  • basic shape rendering
  • texture rendering
  • rendering to a framebuffer
  • input detection (keyboard and mouse)
  • bitmap font

I'm currently researching strategies to implement a gui system.

Check out the examples dir...

drawing a triangle

go run ./examples/triangle

import (
	"github.com/dfirebaugh/banana"
	"golang.org/x/image/colornames"
)

const (
	screenWidth  = 240
	screenHeight = 160
)

func main() {
	banana.SetWindowSize(screenWidth, screenHeight)
	banana.Run(nil, func() {
		banana.Clear(colornames.Skyblue)
		banana.RenderShape(&banana.Polygon{
			Vertices: []banana.Vertex{
				{
					X:     0,
					Y:     float32(screenHeight),
					Color: colornames.Red,
				},
				{
					X:     float32(screenWidth / 2),
					Y:     0,
					Color: colornames.Green,
				},
				{
					X:     float32(screenWidth),
					Y:     float32(screenHeight),
					Color: colornames.Blue,
				},
			},
		})
	})
}

color triangle

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindFramebuffer

func BindFramebuffer(fb graphics.Framebuffer)

func Clear

func Clear(c color.Color)

Clear clears the screen with the specified color.

func Close

func Close()

func DisableFPS

func DisableFPS()

DisableFPS disables the FPS counter in the window title.

func DisableWindowResize

func DisableWindowResize()

func Draw

func Draw()

func EnableFPS

func EnableFPS()

EnableFPS enables the FPS counter in the window title.

func GetCursorPosition

func GetCursorPosition() (int, int)

func GetFPS

func GetFPS() float64

func GetViewportSize

func GetViewportSize() (int, int)

func GetWindowHeight

func GetWindowHeight() int

func GetWindowPosition

func GetWindowPosition() (int, int)

func GetWindowSize

func GetWindowSize() (int, int)

GetWindowSize retrieves the current window size.

func GetWindowWidth

func GetWindowWidth() int

func IsButtonJustPressed

func IsButtonJustPressed(buttonCode input.MouseButton) bool

IsButtonJustPressed checks if a mouse button was just pressed

func IsButtonPressed

func IsButtonPressed(buttonCode input.MouseButton) bool

func IsKeyJustPressed

func IsKeyJustPressed(keyCode input.Key) bool

func IsKeyPressed

func IsKeyPressed(keyCode input.Key) bool

IsKeyPressed checks if a key is currently pressed

func PressButton

func PressButton(buttonCode input.MouseButton)

PressButton simulates a mouse button press

func PressKey

func PressKey(keyCode input.Key)

func ReleaseButton

func ReleaseButton(buttonCode input.MouseButton)

func ReleaseKey

func ReleaseKey(keyCode input.Key)

func RenderFramebuffer

func RenderFramebuffer(fb Framebuffer, options *TextureRenderOptions)

func RenderShape

func RenderShape(shape Renderable)

func RenderText

func RenderText(text string, options *TextRenderOptions)

func RenderTexture

func RenderTexture(textureHandle uint32, options *TextureRenderOptions)

func ResizeFramebuffer

func ResizeFramebuffer(fb Framebuffer, width, height int)

func Run

func Run(updateFn func(), renderFn func())

Run is the main update function called to refresh the engine state.

func RunApp

func RunApp(game Game)

func RunGame

func RunGame(game Game)

func SetBorderlessWindowed

func SetBorderlessWindowed(v bool)

func SetFullScreenBorderless

func SetFullScreenBorderless(v bool)

func SetResizeCallback

func SetResizeCallback(fn func(physicalWidth, physicalHeight uint32))

func SetScrollCallback

func SetScrollCallback(cb func(x float64, y float64))

func SetTitle

func SetTitle(title string)

SetTitle sets the title of the window.

func SetWindowPosition

func SetWindowPosition(x, y int)

func SetWindowSize

func SetWindowSize(width, height int)

func UnbindFramebuffer

func UnbindFramebuffer()

func UpdateTexture

func UpdateTexture(textureID uint32, img image.Image, xOffset, yOffset float32)

func UploadTexture

func UploadTexture(img image.Image) uint32

func Viewport

func Viewport(x int32, y int32, width int32, height int32)

Types

type Circle

type Circle struct {
	X, Y, Radius float32
	Color        color.Color
}

func (*Circle) GetVertices

func (c *Circle) GetVertices(screenWidth, screenHeight int) []graphics.Vertex

type Framebuffer

type Framebuffer graphics.Framebuffer

func AddFramebuffer

func AddFramebuffer(width, height int) (Framebuffer, error)

type Game

type Game interface {
	Update()
	Render()
}

type Polygon

type Polygon struct {
	Vertices []Vertex
}

func (*Polygon) GetVertices

func (t *Polygon) GetVertices(screenWidth, screenHeight int) []graphics.Vertex

type Rect

type Rect struct {
	X, Y, Width, Height, Radius float32
	Color                       color.Color
}

func (*Rect) GetVertices

func (r *Rect) GetVertices(screenWidth, screenHeight int) []graphics.Vertex

func (*Rect) IsWithinBounds

func (r *Rect) IsWithinBounds(px, py float32) bool

type Renderable

type Renderable interface {
	GetVertices(screenWidth, screenHeight int) []graphics.Vertex
}

type Segment

type Segment struct {
	X1, Y1, X2, Y2, Width float32
	Color                 color.Color
	StencilWriteValue     uint8
	StencilTestValue      uint8
}

func (*Segment) GetStencilTestValue

func (l *Segment) GetStencilTestValue() uint8

func (*Segment) GetStencilWriteValue

func (l *Segment) GetStencilWriteValue() uint8

func (*Segment) GetVertices

func (l *Segment) GetVertices(screenWidth, screenHeight int) []graphics.Vertex

type TextRenderOptions

type TextRenderOptions struct {
	X, Y, Size float32
	Color      color.Color
}

type TextureRenderOptions

type TextureRenderOptions struct {
	TextureIndex                int
	X, Y                        float32
	RectWidth, RectHeight       float32
	DesiredWidth, DesiredHeight float32
	Scale                       float32
	RectX, RectY                float32
	Width, Height               float32
	FlipX, FlipY                bool
	Rotation                    float32
}

type Vertex

type Vertex struct {
	X, Y  float32
	Color color.Color
}

Directories

Path Synopsis
examples
fb
gol
gui
exp
Code in the `exp` package is experimental and will likely change
Code in the `exp` package is experimental and will likely change
gui
The gui package is currently expiramental.
The gui package is currently expiramental.
Package graphics provides functionality for 2D graphics rendering, including textures, sprites, text, and shapes.
Package graphics provides functionality for 2D graphics rendering, including textures, sprites, text, and shapes.
pkg
fb
The fb package provides a framebuffer abstraction.
The fb package provides a framebuffer abstraction.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL