gofb

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 13 Imported by: 7

README

gofb

Framebuffer library for golang

Go Report Card PkgGoDev

Example

package main

import (
	"github.com/rostislavjadavan/gofb"
)

func main() {
	// Create Window
	w := gofb.NewWindow("go-fb", 600, 600, false)

	// Create pixel buffer
	surface := gofb.NewSurface(600, 600)

	// Draw pixel into buffer
	surface.SetPixel(300, 300, gofb.NewColor3(255, 255, 255))

	for w.IsRunning() {
		w.StartFrame()
		w.Clear(gofb.ColorBlack)

		// Draw buffer on the screen
		surface.Draw(0, 0)

		w.FinalizeFrame()
	}

	defer surface.Release()
	defer w.Destroy()
}

Features

  • draw pixel by pixel
  • load png, jpg images
  • scale to mimic pixel art
  • use custom ttf font
  • sprite sheets (for tile set rendering)
  • keyboard and mouse input

More examples

Take a look at all the examples in the /examples folder.

Libraries used

License

MIT

Documentation

Index

Constants

View Source
const (
	InputUnknown      = -1
	KeySpace          = 32
	KeyApostrophe     = 39 /* ' */
	KeyComma          = 44 /* , */
	KeyMinus          = 45 /* - */
	KeyPeriod         = 46 /* . */
	KeySlash          = 47 /* / */
	Key0              = 48
	Key1              = 49
	Key2              = 50
	Key3              = 51
	Key4              = 52
	Key5              = 53
	Key6              = 54
	Key7              = 55
	Key8              = 56
	Key9              = 57
	KeySemicolon      = 59 /* ; */
	KeyEqual          = 61 /* = */
	KeyA              = 65
	KeyB              = 66
	KeyC              = 67
	KeyD              = 68
	KeyE              = 69
	KeyF              = 70
	KeyG              = 71
	KeyH              = 72
	KeyI              = 73
	KeyJ              = 74
	KeyK              = 75
	KeyL              = 76
	KeyM              = 77
	KeyN              = 78
	KeyO              = 79
	KeyP              = 80
	KeyQ              = 81
	KeyR              = 82
	KeyS              = 83
	KeyT              = 84
	KeyU              = 85
	KeyV              = 86
	KeyW              = 87
	KeyX              = 88
	KeyY              = 89
	KeyZ              = 90
	KeyLeftBracket    = 91  /* [ */
	KeyBackslash      = 92  /* \ */
	KeyRightBracket   = 93  /* ] */
	KeyGraveAccent    = 96  /* ` */
	KeyWorld1         = 161 /* non-US #1 */
	KeyWorld2         = 162 /* non-US #2 */
	KeyEscape         = 256
	KeyEnter          = 257
	KeyTab            = 258
	KeyBackspace      = 259
	KeyInsert         = 260
	KeyDelete         = 261
	KeyRight          = 262
	KeyLeft           = 263
	KeyDown           = 264
	KeyUp             = 265
	KeyPageUp         = 266
	KeyPageDown       = 267
	KeyHome           = 268
	KeyEnd            = 269
	KeyCapsLock       = 280
	KeyScrollLock     = 281
	KeyNumLock        = 282
	KeyPrintScreen    = 283
	KeyPause          = 284
	KeyF1             = 290
	KeyF2             = 291
	KeyF3             = 292
	KeyF4             = 293
	KeyF5             = 294
	KeyF6             = 295
	KeyF7             = 296
	KeyF8             = 297
	KeyF9             = 298
	KeyF10            = 299
	KeyF11            = 300
	KeyF12            = 301
	KeyF13            = 302
	KeyF14            = 303
	KeyF15            = 304
	KeyF16            = 305
	KeyF17            = 306
	KeyF18            = 307
	KeyF19            = 308
	KeyF20            = 309
	KeyF21            = 310
	KeyF22            = 311
	KeyF23            = 312
	KeyF24            = 313
	KeyF25            = 314
	KeyKp0            = 320
	KeyKp1            = 321
	KeyKp2            = 322
	KeyKp3            = 323
	KeyKp4            = 324
	KeyKp5            = 325
	KeyKp6            = 326
	KeyKp7            = 327
	KeyKp8            = 328
	KeyKp9            = 329
	KeyKpDecimal      = 330
	KeyKpDivide       = 331
	KeyKpMultiply     = 332
	KeyKpSubtract     = 333
	KeyKpAdd          = 334
	KeyKpEnter        = 335
	KeyKpEqual        = 336
	KeyLeftShift      = 340
	KeyLeftControl    = 341
	KeyLeftAlt        = 342
	KeyLeftSuper      = 343
	KeyRightShift     = 344
	KeyRightControl   = 345
	KeyRightAlt       = 346
	KeyRightSuper     = 347
	KeyMenu           = 348
	KeyLast           = 348
	KeyShift          = 401
	KeyControl        = 402
	KeyAlt            = 403
	KeySuper          = 404
	MouseButtonLeft   = 500
	MouseButtonMiddle = 501
	MouseButtonRight  = 502
)

Keyboard and mouse inputs

Variables

View Source
var ColorBlack = Color{R: 0, G: 0, B: 0, A: 255}

ColorBlack is black Color

View Source
var ColorOpaque = Color{R: 0, G: 0, B: 0, A: 0}

ColorOpaque is fully transparent color

View Source
var ColorWhite = Color{R: 255, G: 255, B: 255, A: 255}

ColorWhite is white Color

Functions

This section is empty.

Types

type Color

type Color struct {
	R uint8
	G uint8
	B uint8
	A uint8
}

Color RGBA byte color

func NewColor3 added in v1.1.2

func NewColor3(r uint8, g uint8, b uint8) Color

NewColor3 create new Color (without alpha)

func NewColor4 added in v1.1.2

func NewColor4(r uint8, g uint8, b uint8, a uint8) Color

NewColor4 create new Color with alpha component

func (*Color) GetAsInt added in v1.1.2

func (c *Color) GetAsInt() int

GetAsInt return color as RGBA int value

type Font

type Font struct {
	Handle *gltext.Font
}

Font handle

func NewFont

func NewFont(filename string, size int) (*Font, error)

NewFont create new Font from given filename (.ttf expected)

func (*Font) Draw

func (f *Font) Draw(str string, x, y int, c Color)

Draw text on the screen

func (*Font) Drawv added in v1.1.2

func (f *Font) Drawv(str string, v Vec2, c Color)

Drawv text on the screen

type Region

type Region struct {
	X int
	Y int
	W int
	H int
}

Region Screen region

func NewRegion

func NewRegion(x int, y int, w int, h int) Region

NewRegion create new region

func (*Region) IsInside added in v1.1.2

func (r *Region) IsInside(v Vec2) bool

IsInside return if given vector is inside region

type SpriteSheet

type SpriteSheet struct {
	// contains filtered or unexported fields
}

SpriteSheet represents multiple sprites on one image

func NewSpriteSheetFromFile

func NewSpriteSheetFromFile(file string, tileWidth, tileHeight int) (*SpriteSheet, error)

NewSpriteSheetFromFile create sprite sheet from file

func NewSpriteSheetFromSurface added in v1.1.2

func NewSpriteSheetFromSurface(s *Surface, tileWidth, tileHeight int) (*SpriteSheet, error)

NewSpriteSheetFromSurface create sprite sheet from surface

func (*SpriteSheet) DrawTile

func (s *SpriteSheet) DrawTile(x int, y int, tileX int, tileY int)

DrawTile draw tile

func (*SpriteSheet) Release

func (s *SpriteSheet) Release()

Release release structure from memory

func (*SpriteSheet) SetTileSize

func (s *SpriteSheet) SetTileSize(width int, height int)

SetTileSize set size of one sprite

func (*SpriteSheet) Surface

func (s *SpriteSheet) Surface() *Surface

Surface return surface instance

type Surface

type Surface struct {
	Width          int
	Height         int
	Scale          int
	Rotation       float32
	FlipHorizontal bool
	FlipVertical   bool
	// contains filtered or unexported fields
}

Surface represent pixel buffer

func NewSurface

func NewSurface(width int, height int) *Surface

NewSurface create new empty surface

func NewSurfaceFromBytes

func NewSurfaceFromBytes(width int, height int, bytes *[]byte) *Surface

NewSurfaceFromBytes create new surface from given input byte array (expecting RGBA format)

func NewSurfaceFromFile

func NewSurfaceFromFile(file string) (*Surface, error)

NewSurfaceFromFile create surface from image file

func (*Surface) Clear added in v1.1.2

func (s *Surface) Clear(c Color)

Clear surface with provided color

func (*Surface) Draw

func (s *Surface) Draw(x int, y int)

Draw surface on the screen

func (*Surface) DrawRegion

func (s *Surface) DrawRegion(x int, y int, r Region)

DrawRegion draw region of surface on the screen

func (*Surface) DrawRegionv added in v1.1.2

func (s *Surface) DrawRegionv(v Vec2, r Region)

DrawRegionv draw region of surface on the screen

func (*Surface) Drawv added in v1.1.2

func (s *Surface) Drawv(v Vec2)

Drawv surface on the screen

func (*Surface) GetPixel

func (s *Surface) GetPixel(x int, y int) Color

GetPixel return color of pixel

func (*Surface) GetPixelv added in v1.1.2

func (s *Surface) GetPixelv(v Vec2) Color

GetPixelv return color of pixel

func (*Surface) IsInside added in v1.1.2

func (s *Surface) IsInside(x, y int) bool

IsInside check if given point is inside surface

func (*Surface) IsInsidev added in v1.1.2

func (s *Surface) IsInsidev(v Vec2) bool

IsInsidev check if given point is inside surface

func (*Surface) Release

func (s *Surface) Release()

Release surface from memory and gpu

func (*Surface) SetPixel

func (s *Surface) SetPixel(x int, y int, c Color)

SetPixel draw pixel at surface

func (*Surface) SetPixelv added in v1.1.2

func (s *Surface) SetPixelv(v Vec2, c Color)

SetPixelv draw pixel at surface

type Texture

type Texture struct {
	Handle uint32
	Name   string
	Width  int
	Height int
}

Texture represent OpenGL texture

func NewTextureFromBytes

func NewTextureFromBytes(width int, height int, pixels *[]byte) *Texture

NewTextureFromBytes creates new texture from given byte array (expected is RGBA format)

func (*Texture) Bind

func (t *Texture) Bind()

Bind to texture to current context

func (*Texture) Release

func (t *Texture) Release()

Release texture from gpu memory

func (*Texture) Update

func (t *Texture) Update(width int, height int, pixels *[]byte)

type Vec2 added in v1.1.2

type Vec2 struct {
	X int
	Y int
}

Vec2 2D vector

func NewVec2 added in v1.1.2

func NewVec2(x int, y int) Vec2

NewVec2 return new instance

func (*Vec2) Abs added in v1.1.2

func (v *Vec2) Abs() Vec2

Abs absolute value

func (*Vec2) ClipInside2 added in v1.1.2

func (v *Vec2) ClipInside2(a Vec2, b Vec2)

ClipInside2 Clip vector into given region

func (*Vec2) Clone added in v1.1.2

func (v *Vec2) Clone() Vec2

Clone return copy of vector

func (*Vec2) Distance added in v1.1.2

func (v *Vec2) Distance(v2 Vec2) float64

Distance return distance to given vector

func (*Vec2) IsInside added in v1.1.2

func (v *Vec2) IsInside(a Vec2) bool

IsInside check if vector is inside region

func (*Vec2) IsInside2 added in v1.1.2

func (v *Vec2) IsInside2(a Vec2, b Vec2) bool

IsInside2 check if vector is inside region

func (*Vec2) Lerp added in v1.1.2

func (v *Vec2) Lerp(t float64, target Vec2) Vec2

Lerp linear interpolation between two vectors, t = [0,1]

func (*Vec2) Sub added in v1.1.2

func (v *Vec2) Sub(v2 *Vec2) *Vec2

Sub substract two vectors

func (*Vec2) Subi added in v1.1.2

func (v *Vec2) Subi(i int) *Vec2

Subi substract int from both components

type Vec2f added in v1.1.2

type Vec2f struct {
	X float64
	Y float64
}

Vec2 2D vector

func NewVec2f added in v1.1.2

func NewVec2f(x, y float64) Vec2f

NewVec2f return new instance

type Window

type Window struct {
	Width      int
	Height     int
	Fullscreen bool
	// contains filtered or unexported fields
}

Window represents window object

func NewWindow

func NewWindow(name string, width int, height int, fullscreen bool) *Window

NewWindow create new OpenGL window

func (*Window) Clear

func (w *Window) Clear(c Color)

Clear screen

func (*Window) Destroy

func (w *Window) Destroy()

Destroy will close window

func (*Window) FinalizeFrame

func (w *Window) FinalizeFrame()

FinalizeFrame will swap buffers and poll for events This function needs to be called at the end of the render loop

func (*Window) GetCursorPos

func (w *Window) GetCursorPos() Vec2

GetCursorPos get mouse cursor position

func (*Window) GetDeltaTimeMs

func (w *Window) GetDeltaTimeMs() int64

GetDeltaTimeMs return number of milliseconds elapsed when rendering last frame

func (*Window) GetFPS

func (w *Window) GetFPS() float32

GetFPS get average frames per second

func (*Window) GetTotalElapsedMs

func (w *Window) GetTotalElapsedMs() int64

GetTotalElapsedMs return number of milliseconds elapsed since application started

func (*Window) IsInput

func (w *Window) IsInput(inputCode int) bool

IsInput check if input was pressed

func (*Window) IsRunning

func (w *Window) IsRunning() bool

IsRunning check if application is running

func (*Window) ResetKeyCallback added in v1.1.2

func (w *Window) ResetKeyCallback()

ResetKeyCallback reset back original keyboardcallback

func (*Window) SetKeyCallback added in v1.1.2

func (w *Window) SetKeyCallback(cbfun glfw.KeyCallback)

SetKeyCallback set custom keyboard callback function

func (*Window) StartFrame

func (w *Window) StartFrame()

StartFrame needs to be at the start of the render loop

func (*Window) Stop

func (w *Window) Stop()

Stop running application

Directories

Path Synopsis
examples
animation Module
images Module
keyboard Module
mouse Module
simple Module
text Module
tunnel Module

Jump to

Keyboard shortcuts

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