go13h

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 5 Imported by: 0

README

go-13h is a wrapper for https://github.com/veandco/go-sdl2 that creates a simple method to draw to the screen for Go.

Set up is a little time consuming but relatively easy:

You need to install go-sdl2 found at https://github.com/veandco/go-sdl2, follow its install instrucitons for your setup.

Note: Most linux distros in my experience are behind on their SDL version, so it's best to compile you're own libraries from the most current SDL build or else go-sdl2 won't install

Note: When adding sdl headers to your minGW golder in windows, I have found the %InstallPath%/mingw-w64/x86_64-7.2.0-posix-seh-rt_v5-rev1/mingw64/x86_64-w64-mingw32/ is where you want your dev files

Note: You can build a static application with go-sdl2, I'll be updating these instructions when I have the time to go step by step for the process.

Once you have go sdl2 working properly, you can instal go-13h

go get bitbucket.org/hsoolien/go-13h works on windows but linux tries to use mercurial with bitbucket which in my experinence doesnt' work. I usualy just use git to clone to the approprtiate directory.

The test file I used (this is how I tested go-13h) can be found at bitbucket.org/hsoolien/go-13htest

Documentation

Index

Constants

View Source
const (
	//AlphaNone is no alpha blend for DrawPoint
	AlphaNone = iota
	//AlphaAdd is a basic add alpha for DrawPoint
	AlphaAdd
)

Variables

View Source
var (
	//White color preset
	White color.RGBA
	//Silver color preset
	Silver color.RGBA
	//Gray color preset
	Gray color.RGBA
	//Black color preset
	Black color.RGBA
	//Red color preset
	Red color.RGBA
	//Maroon color preset
	Maroon color.RGBA
	//Orange color preset
	Orange color.RGBA
	//Yellow color preset
	Yellow color.RGBA
	//Olive color preset
	Olive color.RGBA
	//Lime color preset
	Lime color.RGBA
	//Green color preset
	Green color.RGBA
	//Aqua color preset
	Aqua color.RGBA
	//Teal color preset
	Teal color.RGBA
	//Blue color preset
	Blue color.RGBA
	//Navy color preset
	Navy color.RGBA
	//Fuscia color preset
	Fuscia color.RGBA
	//Purple color preset
	Purple color.RGBA
)

Functions

func NewScreen

func NewScreen(w, h, rw, rh int32, n string, fs, vs, lf bool) (*Screen, *Layer, error)

NewScreen sets up package and returns a *Screen to manage the global state as well as a firs *Layer to draw to. Currently only supports a ARGB8888 colour space w, h are the dimensions of the layer you draw to rw, rh are the real dimensions of the window/screen (will scale screen) n is name of Window fs is fullscreen, vs is vSync and lf is linear filtering for screen scaling When quiting, call QuitScreen to close off all SDL assets.

Types

type Image added in v0.0.3

type Image struct {
	Memory []byte
	W, H   int32
}

Image is raw image data with resolution and color context

type Layer

type Layer struct {
	Memory []byte

	W, H int32 //Layer resolution
	A    int   //AlphaMode
	Scr  *Screen

	Hide bool
	// contains filtered or unexported fields
}

Layer contains a screen layer of info, a basic screen always has a 0 layer

func (*Layer) Clear

func (l *Layer) Clear(c color.RGBA)

Clear clears the memory to color

func (*Layer) DrawChar

func (l *Layer) DrawChar(s string, x, y, sc int32, c color.RGBA) error

DrawChar renders character s to x, y scaled sc times

func (*Layer) DrawCharFlip added in v0.0.3

func (l *Layer) DrawCharFlip(s string, x, y, sc int32, c color.RGBA) error

DrawCharFlip renders character s to x, y scaled sc times with y 0 at bottom of screen

func (*Layer) DrawCircleBorder

func (l *Layer) DrawCircleBorder(x, y int32, r float64, c color.RGBA)

DrawCircleBorder makes circle of r radius at x, y using current working color

func (*Layer) DrawCircleFill

func (l *Layer) DrawCircleFill(x, y int32, r1, r2 float64, c color.RGBA)

DrawCircleFill fills a circle from r1 to r2 at x, y using current working color

func (*Layer) DrawLine

func (l *Layer) DrawLine(x, y, x2, y2 int32, c color.RGBA)

DrawLine draws a line from x, y, to x2, y2 using current working color Code derived from examples given here: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm

func (*Layer) DrawPoint

func (l *Layer) DrawPoint(x, y int32, c color.RGBA)

DrawPoint sets a single point on the screen memory to current working color

func (*Layer) DrawRectBorder

func (l *Layer) DrawRectBorder(x, y, w, h int32, c color.RGBA)

DrawRectBorder makes a w wide and h high rectangle, borders ony2 at x, y using current working color

func (*Layer) DrawRectFill

func (l *Layer) DrawRectFill(x, y, w, h int32, c color.RGBA)

DrawRectFill makees a w wide and h high rectangle at x, y using current working color

func (*Layer) DrawString

func (l *Layer) DrawString(s string, x, y, sc int32, c color.RGBA) []error

DrawString renders string s to x, y scaled sc times

func (*Layer) DrawStringFlip added in v0.0.3

func (l *Layer) DrawStringFlip(s string, x, y, sc int32, c color.RGBA) []error

DrawStringFlip renders string s to x,y with y scaled sc times with y 0 at bottom of screen

func (*Layer) FlipX added in v0.0.3

func (l *Layer) FlipX()

FlipX flips layer x axis (0 is now right hand of screen)

func (*Layer) FlipY added in v0.0.3

func (l *Layer) FlipY()

FlipY flips layer y axis (0 is now bottom of screen)

func (*Layer) Offset

func (l *Layer) Offset(x, y float64)

Offset moves the layer in relation to the 0,0 of the final screen resolution

func (*Layer) ReadPoint

func (l *Layer) ReadPoint(x, y int32) (color.RGBA, error)

ReadPoint returns the colour value of location x, y in layer memory

func (*Layer) Rotate

func (l *Layer) Rotate(r float64, p *sdl.Point)

Rotate rotates layer around point by r

func (*Layer) Scale

func (l *Layer) Scale(sx, sy float64)

Scale scales layer by s

type Screen

type Screen struct {
	Layers []*Layer //Slice of screen layers
	W, H   int32    //Screen resolution

	CharHeight, CharWidth int32
	CharSpace,
	CharExclaim,
	CharDblQuote,
	CharHash,
	CharString,
	CharPercent,
	CharAmp,
	CharApostrophe,
	CharOpenBracketCurved,
	CharCloseBracketCurved,
	CharAsterisks,
	CharPlus,
	CharComma,
	CharMinus,
	CharPeriod,
	CharForwardSlash,
	Char0,
	Char1,
	Char2,
	Char3,
	Char4,
	Char5,
	Char6,
	Char7,
	Char8,
	Char9,
	CharColon,
	CharSemiColon,
	CharLessThan,
	CharEqual,
	CharGreaterThan,
	CharQuestion,
	CharAt,
	CharA,
	CharB,
	CharC,
	CharD,
	CharE,
	CharF,
	CharG,
	CharH,
	CharI,
	CharJ,
	CharK,
	CharL,
	CharM,
	CharN,
	CharO,
	CharP,
	CharQ,
	CharR,
	CharS,
	CharT,
	CharU,
	CharV,
	CharW,
	CharX,
	CharY,
	CharZ,
	CharOpenBracketSquare,
	CharBackSlash,
	CharCloseBracketSquare,
	CharCarrot,
	CharUnderScore,
	CharBackTick,
	Chara,
	Charb,
	Charc,
	Chard,
	Chare,
	Charf,
	Charg,
	Charh,
	Chari,
	Charj,
	Chark,
	Charl,
	Charm,
	Charn,
	Charo,
	Charp,
	Charq,
	Charr,
	Chars,
	Chart,
	Charu,
	Charv,
	Charw,
	Charx,
	Chary,
	Charz,
	CharOpenCurleyBrace,
	CharPipe,
	CharCloseCurleyBrace,
	CharTilde,
	CharNoChar string
	// contains filtered or unexported fields
}

Screen manages the global state of go13h, and holds some useful info (ex character set) Screen also manages layer ordering and final rendering

func (*Screen) NewLayer

func (scr *Screen) NewLayer(w, h int32, lf bool) (*Layer, error)

NewLayer sets up and registers a new *Layer, note layers do not have to be the same width, height or texture filtering as other layers Layers can take up a lot of memory very easily, they take up their current working Memory, as well as the memory required for the backing texture ex: a 1920x1080 layer takes up 16Megabytes of RAM at minimum

func (*Screen) QuitScreen

func (scr *Screen) QuitScreen()

QuitScreen closes off SDL assets

func (*Screen) Update

func (scr *Screen) Update() error

Update refreshes display

Jump to

Keyboard shortcuts

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