sfb

package module
v0.0.0-...-8afd523 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: MIT Imports: 4 Imported by: 0

README

sfb

This is kind of an expiremental project and possibly a bad idea. So, I wouldn't necessarily recommend using it.

high level goal

build a software renderer that can be used reasonably easily on machines with low or no gpu

justifications
  • to get some experience writing a wrapper around C for go libraries
  • to explore the possibilities of making a software renderer (for machines with no gpu)
  • to get some concurrency reps in
how does it work?
  1. The C layer calls SDL2 to load a window.
  2. We create a texture.
  3. we fill a buffer with pixels and then load it to that texture
  4. a small api is exposed through a shared object file
  5. there's a go wrapper library that hooks into that .so file and allows us to set individual pixels in the buffer
  6. to draw shapes, we use some well known drawing algorithms that I tried to concurrency-ify

obviously, there are some limitations here. Like the larger your window is the slower it will run and the cost of rendering a shape is bound to the size of the shape. However, I was able to get these circles moving around at over 100fps (granted that's on a computer that has a pretty fast cpu)

I'd like to play around with rewriting the drawing functions in C to explore simd operations. That's unexplored terrority for me, but maybe I'll jump down that rabbit hole someday.

how to run

You need sdl on your system:

apt install libsdl2-dev
make # make the .so file
go run ./examples/big_circle/ # run one of the examples

Documentation

Index

Constants

View Source
const (
	FB_QUIT       = C.SDL_QUIT
	FB_KEYDOWN    = C.SDL_KEYDOWN
	FB_KEY_ESCAPE = C.SDLK_ESCAPE
)

Variables

This section is empty.

Functions

func PollEvent

func PollEvent() (eventType, keySym uint32, eventAvailable bool)

func Run

func Run(update func(s Screen))

Types

type Pixel

type Pixel struct {
	R, G, B, A uint8
}

type Screen

type Screen interface {
	SetWidth(width int16)
	SetHeight(height int16)
	SetTitle(title string)
	EnableFPS()
	// contains filtered or unexported methods
}

Directories

Path Synopsis
examples
pkg
draw
draw is a package from drawing with the cpu
draw is a package from drawing with the cpu
geom
The geom package provides basic geometry types and functions.
The geom package provides basic geometry types and functions.

Jump to

Keyboard shortcuts

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