gofb

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 12 Imported by: 7

README

gofb

Framebuffer library for golang

Go Report Card go.dev reference

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.NewColor(255, 255, 255, 255))

	for w.IsRunning() {
		w.StartFrame()
		w.Clear(gofb.NewColor(0, 0, 0, 255))

		// Draw buffer on 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
  • draw sub region of image
  • keyboard and mouse input

More examples

http://github.com/rostislavjadavan/gofb-examples

Libraries used

http://github.com/rostislavjadavan/gofb-logo

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{/* contains filtered or unexported fields */}

ColorBlack is black Color

View Source
var ColorWhite = Color{/* contains filtered or unexported fields */}

ColorWhite is white Color

Functions

This section is empty.

Types

type Color

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

Color RGBA byte color

func NewColor

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

NewColor create new Color

func (*Color) GL

func (c *Color) GL()

GL set color to OpenGL context

func (*Color) GLClear

func (c *Color) GLClear()

GLClear set color as OpenGL color for clearing the screen

type Font

type Font struct {
	Handle *gltext.Font
}

Font handle

func NewFont

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

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

func (*Font) Draw

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

Draw text on the screen

type Point2

type Point2 struct {
	X float32
	Y float32
}

Point2 2D point

func NewPoint2

func NewPoint2(x float32, y float32) Point2

NewPoint2 create new Point

func (*Point2) GL

func (p *Point2) GL()

GL set point as OpenGL vertex

type Region

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

Region Screen region

func NewRegion

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

NewRegion create new region

type Surface

type Surface struct {
	Width    int
	Height   int
	Scale    int
	Rotation float32
	// 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) 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) GetPixel

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

GetPixel return color of pixel

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

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

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() Point2

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