pixels

package
v0.2.0-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MouseButton1      = Button(glfw.MouseButton1)
	MouseButton2      = Button(glfw.MouseButton2)
	MouseButton3      = Button(glfw.MouseButton3)
	MouseButton4      = Button(glfw.MouseButton4)
	MouseButton5      = Button(glfw.MouseButton5)
	MouseButton6      = Button(glfw.MouseButton6)
	MouseButton7      = Button(glfw.MouseButton7)
	MouseButton8      = Button(glfw.MouseButton8)
	MouseButtonLast   = Button(glfw.MouseButtonLast)
	MouseButtonLeft   = Button(glfw.MouseButtonLeft)
	MouseButtonRight  = Button(glfw.MouseButtonRight)
	MouseButtonMiddle = Button(glfw.MouseButtonMiddle)
)

List of all mouse buttons.

View Source
const (
	KeyUnknown      = Button(glfw.KeyUnknown)
	KeySpace        = Button(glfw.KeySpace)
	KeyApostrophe   = Button(glfw.KeyApostrophe)
	KeyComma        = Button(glfw.KeyComma)
	KeyMinus        = Button(glfw.KeyMinus)
	KeyPeriod       = Button(glfw.KeyPeriod)
	KeySlash        = Button(glfw.KeySlash)
	Key0            = Button(glfw.Key0)
	Key1            = Button(glfw.Key1)
	Key2            = Button(glfw.Key2)
	Key3            = Button(glfw.Key3)
	Key4            = Button(glfw.Key4)
	Key5            = Button(glfw.Key5)
	Key6            = Button(glfw.Key6)
	Key7            = Button(glfw.Key7)
	Key8            = Button(glfw.Key8)
	Key9            = Button(glfw.Key9)
	KeySemicolon    = Button(glfw.KeySemicolon)
	KeyEqual        = Button(glfw.KeyEqual)
	KeyA            = Button(glfw.KeyA)
	KeyB            = Button(glfw.KeyB)
	KeyC            = Button(glfw.KeyC)
	KeyD            = Button(glfw.KeyD)
	KeyE            = Button(glfw.KeyE)
	KeyF            = Button(glfw.KeyF)
	KeyG            = Button(glfw.KeyG)
	KeyH            = Button(glfw.KeyH)
	KeyI            = Button(glfw.KeyI)
	KeyJ            = Button(glfw.KeyJ)
	KeyK            = Button(glfw.KeyK)
	KeyL            = Button(glfw.KeyL)
	KeyM            = Button(glfw.KeyM)
	KeyN            = Button(glfw.KeyN)
	KeyO            = Button(glfw.KeyO)
	KeyP            = Button(glfw.KeyP)
	KeyQ            = Button(glfw.KeyQ)
	KeyR            = Button(glfw.KeyR)
	KeyS            = Button(glfw.KeyS)
	KeyT            = Button(glfw.KeyT)
	KeyU            = Button(glfw.KeyU)
	KeyV            = Button(glfw.KeyV)
	KeyW            = Button(glfw.KeyW)
	KeyX            = Button(glfw.KeyX)
	KeyY            = Button(glfw.KeyY)
	KeyZ            = Button(glfw.KeyZ)
	KeyLeftBracket  = Button(glfw.KeyLeftBracket)
	KeyBackslash    = Button(glfw.KeyBackslash)
	KeyRightBracket = Button(glfw.KeyRightBracket)
	KeyGraveAccent  = Button(glfw.KeyGraveAccent)
	KeyWorld1       = Button(glfw.KeyWorld1)
	KeyWorld2       = Button(glfw.KeyWorld2)
	KeyEscape       = Button(glfw.KeyEscape)
	KeyEnter        = Button(glfw.KeyEnter)
	KeyTab          = Button(glfw.KeyTab)
	KeyBackspace    = Button(glfw.KeyBackspace)
	KeyInsert       = Button(glfw.KeyInsert)
	KeyDelete       = Button(glfw.KeyDelete)
	KeyRight        = Button(glfw.KeyRight)
	KeyLeft         = Button(glfw.KeyLeft)
	KeyDown         = Button(glfw.KeyDown)
	KeyUp           = Button(glfw.KeyUp)
	KeyPageUp       = Button(glfw.KeyPageUp)
	KeyPageDown     = Button(glfw.KeyPageDown)
	KeyHome         = Button(glfw.KeyHome)
	KeyEnd          = Button(glfw.KeyEnd)
	KeyCapsLock     = Button(glfw.KeyCapsLock)
	KeyScrollLock   = Button(glfw.KeyScrollLock)
	KeyNumLock      = Button(glfw.KeyNumLock)
	KeyPrintScreen  = Button(glfw.KeyPrintScreen)
	KeyPause        = Button(glfw.KeyPause)
	KeyF1           = Button(glfw.KeyF1)
	KeyF2           = Button(glfw.KeyF2)
	KeyF3           = Button(glfw.KeyF3)
	KeyF4           = Button(glfw.KeyF4)
	KeyF5           = Button(glfw.KeyF5)
	KeyF6           = Button(glfw.KeyF6)
	KeyF7           = Button(glfw.KeyF7)
	KeyF8           = Button(glfw.KeyF8)
	KeyF9           = Button(glfw.KeyF9)
	KeyF10          = Button(glfw.KeyF10)
	KeyF11          = Button(glfw.KeyF11)
	KeyF12          = Button(glfw.KeyF12)
	KeyF13          = Button(glfw.KeyF13)
	KeyF14          = Button(glfw.KeyF14)
	KeyF15          = Button(glfw.KeyF15)
	KeyF16          = Button(glfw.KeyF16)
	KeyF17          = Button(glfw.KeyF17)
	KeyF18          = Button(glfw.KeyF18)
	KeyF19          = Button(glfw.KeyF19)
	KeyF20          = Button(glfw.KeyF20)
	KeyF21          = Button(glfw.KeyF21)
	KeyF22          = Button(glfw.KeyF22)
	KeyF23          = Button(glfw.KeyF23)
	KeyF24          = Button(glfw.KeyF24)
	KeyF25          = Button(glfw.KeyF25)
	KeyKP0          = Button(glfw.KeyKP0)
	KeyKP1          = Button(glfw.KeyKP1)
	KeyKP2          = Button(glfw.KeyKP2)
	KeyKP3          = Button(glfw.KeyKP3)
	KeyKP4          = Button(glfw.KeyKP4)
	KeyKP5          = Button(glfw.KeyKP5)
	KeyKP6          = Button(glfw.KeyKP6)
	KeyKP7          = Button(glfw.KeyKP7)
	KeyKP8          = Button(glfw.KeyKP8)
	KeyKP9          = Button(glfw.KeyKP9)
	KeyKPDecimal    = Button(glfw.KeyKPDecimal)
	KeyKPDivide     = Button(glfw.KeyKPDivide)
	KeyKPMultiply   = Button(glfw.KeyKPMultiply)
	KeyKPSubtract   = Button(glfw.KeyKPSubtract)
	KeyKPAdd        = Button(glfw.KeyKPAdd)
	KeyKPEnter      = Button(glfw.KeyKPEnter)
	KeyKPEqual      = Button(glfw.KeyKPEqual)
	KeyLeftShift    = Button(glfw.KeyLeftShift)
	KeyLeftControl  = Button(glfw.KeyLeftControl)
	KeyLeftAlt      = Button(glfw.KeyLeftAlt)
	KeyLeftSuper    = Button(glfw.KeyLeftSuper)
	KeyRightShift   = Button(glfw.KeyRightShift)
	KeyRightControl = Button(glfw.KeyRightControl)
	KeyRightAlt     = Button(glfw.KeyRightAlt)
	KeyRightSuper   = Button(glfw.KeyRightSuper)
	KeyMenu         = Button(glfw.KeyMenu)
	KeyLast         = Button(glfw.KeyLast)
)

List of all keyboard buttons.

View Source
const (
	Joystick1  = Joystick(glfw.Joystick1)
	Joystick2  = Joystick(glfw.Joystick2)
	Joystick3  = Joystick(glfw.Joystick3)
	Joystick4  = Joystick(glfw.Joystick4)
	Joystick5  = Joystick(glfw.Joystick5)
	Joystick6  = Joystick(glfw.Joystick6)
	Joystick7  = Joystick(glfw.Joystick7)
	Joystick8  = Joystick(glfw.Joystick8)
	Joystick9  = Joystick(glfw.Joystick9)
	Joystick10 = Joystick(glfw.Joystick10)
	Joystick11 = Joystick(glfw.Joystick11)
	Joystick12 = Joystick(glfw.Joystick12)
	Joystick13 = Joystick(glfw.Joystick13)
	Joystick14 = Joystick(glfw.Joystick14)
	Joystick15 = Joystick(glfw.Joystick15)
	Joystick16 = Joystick(glfw.Joystick16)

	JoystickLast = Joystick(glfw.JoystickLast)
)

List all of the joysticks.

View Source
const (
	AxisLeftX        = GamepadAxis(glfw.AxisLeftX)
	AxisLeftY        = GamepadAxis(glfw.AxisLeftY)
	AxisRightX       = GamepadAxis(glfw.AxisRightX)
	AxisRightY       = GamepadAxis(glfw.AxisRightY)
	AxisLeftTrigger  = GamepadAxis(glfw.AxisLeftTrigger)
	AxisRightTrigger = GamepadAxis(glfw.AxisRightTrigger)
	AxisLast         = GamepadAxis(glfw.AxisLast)
)

Gamepad axis IDs.

Gamepad button IDs.

Variables

View Source
var (
	Center      = Anchor{0.5, 0.5}
	Top         = Anchor{0.5, 0}
	TopRight    = Anchor{0, 0}
	Right       = Anchor{0, 0.5}
	BottomRight = Anchor{0, 1}
	Bottom      = Anchor{0.5, 1}
	BottomLeft  = Anchor{1, 1}
	Left        = Anchor{1, 0.5}
	TopLeft     = Anchor{1, 0}
)
View Source
var ASCII []rune

ASCII is a set of all ASCII runes. These runes are codepoints from 32 to 127 inclusive.

View Source
var IM = Matrix{1, 0, 0, 1, 0, 0}

IM stands for identity matrix. Does nothing, no transformation.

View Source
var RGBAModel = color.ModelFunc(rgbaModel)

RGBAModel converts colors to RGBA format.

View Source
var ZR = Rect{Min: ZV, Max: ZV}

ZR is a zero rectangle.

View Source
var ZV = Vec{0, 0}

ZV is a zero vector.

Functions

func GLGetTime

func GLGetTime() float64

func GLRun

func GLRun(run func())

func RangeTable

func RangeTable(table *unicode.RangeTable) []rune

RangeTable takes a *unicode.RangeTable and generates a set of runes contained within that RangeTable.

Types

type Anchor

type Anchor Vec

Anchor is a vector used to define anchors, such as `Center`, `Top`, `TopRight`, etc.

func (Anchor) Opposite

func (anchor Anchor) Opposite() Anchor

Opposite returns the opposite position of the anchor (ie. Top -> Bottom; BottomLeft -> TopRight, etc.).

func (Anchor) String

func (anchor Anchor) String() string

String returns the string representation of an anchor.

type Atlas

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

Atlas is a set of pre-drawn glyphs of a fixed set of runes. This allows for efficient text drawing.

var Atlas7x13 *Atlas

Atlas7x13 is an Atlas using basicfont.Face7x13 with the ASCII rune set

func NewAtlas

func NewAtlas(face font.Face, runeSets ...[]rune) *Atlas

NewAtlas creates a new Atlas containing glyphs of the union of the given sets of runes (plus unicode.ReplacementChar) from the given font face.

Creating an Atlas is rather expensive, do not create a new Atlas each frame.

Do not destroy or close the font.Face after creating the Atlas. Atlas still uses it.

func (*Atlas) Ascent

func (a *Atlas) Ascent() float64

Ascent returns the distance from the top of the line to the baseline.

func (*Atlas) Contains

func (a *Atlas) Contains(r rune) bool

Contains reports wheter r in contained within the Atlas.

func (*Atlas) Descent

func (a *Atlas) Descent() float64

Descent returns the distance from the baseline to the bottom of the line.

func (*Atlas) DrawRune

func (a *Atlas) DrawRune(prevR, r rune, dot Vec) (rect, frame, bounds Rect, newDot Vec)

DrawRune returns parameters necessary for drawing a rune glyph.

Rect is a rectangle where the glyph should be positioned. Frame is the glyph frame inside the Atlas's IPicture. NewDot is the new position of the dot.

func (*Atlas) Glyph

func (a *Atlas) Glyph(r rune) Glyph

Glyph returns the description of r within the Atlas.

func (*Atlas) Kern

func (a *Atlas) Kern(r0, r1 rune) float64

Kern returns the kerning distance between runes r0 and r1. Positive distance means that the glyphs should be further apart.

func (*Atlas) LineHeight

func (a *Atlas) LineHeight() float64

LineHeight returns the recommended vertical distance between two lines of text.

func (*Atlas) Picture

func (a *Atlas) Picture() IPicture

IPicture returns the underlying IPicture containing an arrangement of all the glyphs contained within the Atlas.

type Batch

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

Batch is a ITarget that allows for efficient drawing of many objects with the same IPicture.

To put an object into a Batch, just draw it onto it:

object.Draw(batch)

func NewBatch

func NewBatch(container ITriangles, pic IPicture) *Batch

NewBatch creates an empty Batch with the specified IPicture and container.

The container is where objects get accumulated. Batch will support precisely those ITriangles properties, that the supplied container supports. If you retain access to the container and change it, call Dirty to notify Batch about the change.

Note, that if the container does not support ITrianglesColor, color masking will not work.

func (*Batch) Clear

func (b *Batch) Clear()

Clear removes all objects from the Batch.

func (*Batch) Dirty

func (b *Batch) Dirty()

Dirty notifies Batch about an external modification of it's container. If you retain access to the Batch's container and change it, call Dirty to notify Batch about the change.

container := &pixel.TrianglesData{}
batch := pixel.NewBatch(container, nil)
container.SetLen(10) // container changed from outside of Batch
batch.Dirty()        // notify Batch about the change

func (*Batch) Draw

func (b *Batch) Draw(t ITarget)

Draw draws all objects that are currently in the Batch onto another ITarget.

func (*Batch) MakePicture

func (b *Batch) MakePicture(p IPicture) ITargetPicture

MakePicture returns a specialized copy of the provided IPicture that draws onto this Batch.

func (*Batch) MakeTriangles

func (b *Batch) MakeTriangles(t ITriangles) ITargetTriangles

MakeTriangles returns a specialized copy of the provided ITriangles that draws onto this Batch.

func (*Batch) SetColorMask

func (b *Batch) SetColorMask(c color.Color)

SetColorMask sets a mask color used in the following draws onto the Batch.

func (*Batch) SetMatrix

func (b *Batch) SetMatrix(m Matrix)

SetMatrix sets a Matrix that every point will be projected by.

type Button

type Button int

Button is a keyboard or mouse button. Why distinguish?

func (Button) String

func (b Button) String() string

String returns a human-readable string describing the Button.

type CacheMode

type CacheMode int
const (
	CacheModeDisable       CacheMode = 0
	CacheModePicture       CacheMode = 1
	CacheModePictureUpdate CacheMode = 2
	CacheModeUpdate        CacheMode = 3
)

type Circle

type Circle struct {
	Center Vec
	Radius float64
}

func MakeCircle

func MakeCircle(center Vec, radius float64) Circle

func (Circle) Area

func (c Circle) Area() float64

func (Circle) Contains

func (c Circle) Contains(u Vec) bool

func (Circle) Formula

func (c Circle) Formula() (h, k float64)

func (Circle) Intersect

func (c Circle) Intersect(d Circle) Circle

Intersect returns the maximal Circle which is covered by both `c` and `d`.

If `c` and `d` don't overlap, this function returns a zero-sized circle at the centerpoint between the two Circle's centers.

func (Circle) IntersectLine

func (c Circle) IntersectLine(l Line) Vec

IntersectLine will return the shortest Vec such that if the Circle is moved by the Vec returned, the Line and Rect no longer intersect.

func (Circle) IntersectRect

func (c Circle) IntersectRect(r Rect) Vec

IntersectRect returns a minimal required Vector, such that moving the circle by that vector would stop the Circle and the Rect intersecting. This function returns a zero-vector if the Circle and Rect do not overlap, and if only the perimeters touch.

This function will return a non-zero vector if:

  • The Rect contains the Circle, partially or fully
  • The Circle contains the Rect, partially of fully

func (Circle) IntersectionPoints

func (c Circle) IntersectionPoints(l Line) []Vec

IntersectionPoints returns all the points where the Circle intersects with the line provided. This can be zero, one or two points, depending on the location of the shapes. The points of intersection will be returned in order of closest-to-l.A to closest-to-l.B.

func (Circle) Moved

func (c Circle) Moved(delta Vec) Circle

func (Circle) Norm

func (c Circle) Norm() Circle

func (Circle) Resized

func (c Circle) Resized(radiusDelta float64) Circle

func (Circle) String

func (c Circle) String() string

func (Circle) Union

func (c Circle) Union(d Circle) Circle

type ComposeMethod

type ComposeMethod int

ComposeMethod is a Porter-Duff composition method.

const (
	ComposeOver ComposeMethod = iota
	ComposeIn
	ComposeOut
	ComposeAtop
	ComposeRover
	ComposeRin
	ComposeRout
	ComposeRatop
	ComposeXor
	ComposePlus
	ComposeCopy
)

Here's the list of all available Porter-Duff composition methods. Use ComposeOver for the basic alpha blending.

func (ComposeMethod) Compose

func (cm ComposeMethod) Compose(a, b RGBA) RGBA

Compose composes two colors together according to the ComposeMethod. A is the foreground, B is the background.

type ComposeTarget

type ComposeTarget interface {
	IBasicTarget

	// SetComposeMethod sets a Porter-Duff composition method to be used.
	SetComposeMethod(ComposeMethod)
}

ComposeTarget is a IBasicTarget capable of Porter-Duff composition.

type Drawer

type Drawer struct {
	Triangles ITriangles
	Picture   IPicture
	Cached    CacheMode
	// contains filtered or unexported fields
}

Drawer glues all the fundamental interfaces (ITarget, ITriangles, IPicture) into a coherent and the only intended usage pattern.

Drawer makes it possible to draw any combination of ITriangles and IPicture onto any ITarget efficiently.

To create a Drawer, just assign it's ITriangles and IPicture fields:

d := pixel.Drawer{ITriangles: t, IPicture: p}

If ITriangles is nil, nothing will be drawn. If IPicture is nil, ITriangles will be drawn without a IPicture.

Whenever you change the ITriangles, call Dirty to notify Drawer that ITriangles changed. You don't need to notify Drawer about a change of the IPicture.

Note, that Drawer caches the results of MakePicture from Targets it's drawn to for each IPicture it's set to. What it means is that using a Drawer with an unbounded number of Pictures leads to a memory leak, since Drawer caches them and never forgets. In such a situation, create a new Drawer for each IPicture.

func (*Drawer) Dirty

func (d *Drawer) Dirty()

Dirty marks the ITriangles of this Drawer as changed. If not called, changes will not be visible when drawing.

func (*Drawer) Draw

func (d *Drawer) Draw(t ITarget)

Draw efficiently draws ITriangles with IPicture onto the provided ITarget.

If ITriangles is nil, nothing will be drawn. If IPicture is nil, ITriangles will be drawn without a IPicture.

type EndShape

type EndShape int
const (
	NoEndShape EndShape = iota
	SharpEndShape
	RoundEndShape
)

type GLCanvas

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

GLCanvas is an off-screen rectangular IBasicTarget and IPicture at the same time, that you can draw onto.

It supports ITrianglesPosition, ITrianglesColor, ITrianglesPicture and IPictureColor.

func NewGLCanvas

func NewGLCanvas(bounds Rect, smooth bool) *GLCanvas

NewGLCanvas creates a new empty, fully transparent GLCanvas with given bounds.

func (*GLCanvas) Bounds

func (c *GLCanvas) Bounds() Rect

Bounds returns the rectangular bounds of the GLCanvas.

func (*GLCanvas) Clear

func (c *GLCanvas) Clear(color color.Color)

Clear fills the whole GLCanvas with a single color.

func (*GLCanvas) Color

func (c *GLCanvas) Color(at Vec) RGBA

Color returns the color of the pixel over the given position inside the GLCanvas.

func (*GLCanvas) Draw

func (c *GLCanvas) Draw(t ITarget, matrix Matrix)

Draw draws the content of the GLCanvas onto another ITarget, transformed by the given Matrix, just like if it was a Sprite containing the whole GLCanvas.

func (*GLCanvas) DrawColorMask

func (c *GLCanvas) DrawColorMask(t ITarget, matrix Matrix, mask color.Color)

DrawColorMask draws the content of the GLCanvas onto another ITarget, transformed by the given Matrix and multiplied by the given mask, just like if it was a Sprite containing the whole GLCanvas.

If the color mask is nil, a fully opaque white mask will be used causing no effect.

func (*GLCanvas) Frame

func (c *GLCanvas) Frame() *executor.Frame

Frame returns the underlying OpenGL Frame of this GLCanvas.

func (*GLCanvas) MakePicture

func (c *GLCanvas) MakePicture(p IPicture) ITargetPicture

MakePicture create a specialized copy of the supplied IPicture that draws onto this GLCanvas.

IPictureColor is supported.

func (*GLCanvas) MakeTriangles

func (c *GLCanvas) MakeTriangles(t ITriangles) ITargetTriangles

MakeTriangles creates a specialized copy of the supplied ITriangles that draws onto this GLCanvas.

ITrianglesPosition, ITrianglesColor and ITrianglesPicture are supported.

func (*GLCanvas) Pixels

func (c *GLCanvas) Pixels() []uint8

Pixels returns an alpha-premultiplied RGBA sequence of the content of the GLCanvas.

func (*GLCanvas) SetBounds

func (c *GLCanvas) SetBounds(bounds Rect)

SetBounds resizes the GLCanvas to the new bounds. Old content will be preserved.

func (*GLCanvas) SetColorMask

func (c *GLCanvas) SetColorMask(col color.Color)

SetColorMask sets a color that every color in triangles or a picture will be multiplied by.

func (*GLCanvas) SetComposeMethod

func (c *GLCanvas) SetComposeMethod(cmp ComposeMethod)

SetComposeMethod sets a Porter-Duff composition method to be used in the following draws onto this GLCanvas.

func (*GLCanvas) SetFragmentShader

func (c *GLCanvas) SetFragmentShader(src string)

SetFragmentShader allows you to set a new fragment shader on the underlying framebuffer. Argument "src" is the GLSL source, not a filename.

func (*GLCanvas) SetMatrix

func (c *GLCanvas) SetMatrix(m Matrix)

SetMatrix sets a Matrix that every point will be projected by.

func (*GLCanvas) SetPixels

func (c *GLCanvas) SetPixels(pixels []uint8)

SetPixels replaces the content of the GLCanvas with the provided pixels. The provided slice must be an alpha-premultiplied RGBA sequence of correct length (4 * width * height).

func (*GLCanvas) SetSmooth

func (c *GLCanvas) SetSmooth(smooth bool)

SetSmooth sets whether stretched Pictures drawn onto this GLCanvas should be drawn smooth or pixely.

func (*GLCanvas) SetUniform

func (c *GLCanvas) SetUniform(name string, value interface{})

SetUniform will update the named uniform with the value of any supported underlying attribute variable. If the uniform already exists, including defaults, they will be reassigned to the new value. The value can be a pointer.

func (*GLCanvas) Smooth

func (c *GLCanvas) Smooth() bool

Smooth returns whether stretched Pictures drawn onto this GLCanvas are set to be drawn smooth or pixely.

func (*GLCanvas) Texture

func (c *GLCanvas) Texture() *executor.Texture

Texture returns the underlying OpenGL Texture of this GLCanvas.

Implements GLPicture interface.

type GLFrame

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

func NewGLFrame

func NewGLFrame(bounds Rect) *GLFrame

func (*GLFrame) Bounds

func (gf *GLFrame) Bounds() Rect

func (*GLFrame) Color

func (gf *GLFrame) Color(at Vec) RGBA

func (*GLFrame) Dirty

func (gf *GLFrame) Dirty()

func (*GLFrame) Frame

func (gf *GLFrame) Frame() *executor.Frame

func (*GLFrame) SetBounds

func (gf *GLFrame) SetBounds(bounds Rect)

func (*GLFrame) Texture

func (gf *GLFrame) Texture() *executor.Texture

type GLJoystick

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

type GLMonitor

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

GLMonitor represents a physical display attached to your computer.

func Monitors

func Monitors() []*GLMonitor

Monitors returns a slice of all currently available monitors.

func PrimaryMonitor

func PrimaryMonitor() *GLMonitor

PrimaryMonitor returns the main monitor (usually the one with the taskbar and stuff).

func (*GLMonitor) BitDepth

func (m *GLMonitor) BitDepth() (red, green, blue int)

BitDepth returns the number of bits per color of the GLMonitor.

func (*GLMonitor) Name

func (m *GLMonitor) Name() string

Name returns a human-readable name of the GLMonitor.

func (*GLMonitor) PhysicalSize

func (m *GLMonitor) PhysicalSize() (width, height float64)

PhysicalSize returns the size of the display area of the GLMonitor in millimeters.

func (*GLMonitor) Position

func (m *GLMonitor) Position() (x, y float64)

Position returns the position of the upper-left corner of the GLMonitor in screen coordinates.

func (*GLMonitor) RefreshRate

func (m *GLMonitor) RefreshRate() (rate float64)

RefreshRate returns the refresh frequency of the GLMonitor in Hz (refreshes/second).

func (*GLMonitor) Size

func (m *GLMonitor) Size() (width, height float64)

Size returns the resolution of the GLMonitor in pixels.

func (*GLMonitor) VideoModes

func (m *GLMonitor) VideoModes() (vmodes []VideoMode)

VideoModes returns all available video modes for the monitor.

type GLPicture

type GLPicture interface {
	IPictureColor
	Texture() *executor.Texture
	Update(p IPicture)
}

func NewGLPicture

func NewGLPicture(p IPicture) GLPicture

type GLShader

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

func NewGLShader

func NewGLShader(fragmentShader string) *GLShader

func (*GLShader) SetUniform

func (gs *GLShader) SetUniform(name string, value interface{})

func (*GLShader) Update

func (gs *GLShader) Update()

type GLTriangles

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

func NewGLTriangles

func NewGLTriangles(shader *GLShader, t ITriangles) *GLTriangles

NewGLTriangles returns GLTriangles initialized with the data from the supplied ITriangles.

Only draw the ITriangles using the provided Shader.

func (*GLTriangles) ClipRect

func (gt *GLTriangles) ClipRect(i int) (rect Rect, is bool)

ClipRect returns the Clipping rectangle property of the i-th vertex.

func (*GLTriangles) Color

func (gt *GLTriangles) Color(i int) RGBA

Color returns the Color property of the i-th vertex.

func (*GLTriangles) Copy

func (gt *GLTriangles) Copy() ITriangles

func (*GLTriangles) CopyVertices

func (gt *GLTriangles) CopyVertices()

CopyVertices copies the GLTriangle data down to the vertex data.

func (*GLTriangles) Len

func (gt *GLTriangles) Len() int

Len returns the number of vertices.

func (*GLTriangles) Picture

func (gt *GLTriangles) Picture(i int) (pic Vec, intensity float64)

IPicture returns the IPicture property of the i-th vertex.

func (*GLTriangles) Position

func (gt *GLTriangles) Position(i int) Vec

Position returns the Position property of the i-th vertex.

func (*GLTriangles) SetClipRect

func (gt *GLTriangles) SetClipRect(i int, rect Rect)

SetClipRect sets the Clipping rectangle property of the i-th vertex.

func (*GLTriangles) SetColor

func (gt *GLTriangles) SetColor(i int, c RGBA)

SetColor sets the color property of the i-th vertex.

func (*GLTriangles) SetLen

func (gt *GLTriangles) SetLen(length int)

SetLen efficiently resizes GLTriangles to len.

Time complexity is amortized O(1).

func (*GLTriangles) SetPicture

func (gt *GLTriangles) SetPicture(i int, pic Vec, intensity float64)

SetPicture sets the picture property of the i-th vertex.

func (*GLTriangles) SetPosition

func (gt *GLTriangles) SetPosition(i int, p Vec)

SetPosition sets the position property of the i-th vertex.

func (*GLTriangles) Shader

func (gt *GLTriangles) Shader() *GLShader

Shader returns the GLTriangles's associated shader.

func (*GLTriangles) Slice

func (gt *GLTriangles) Slice(i, j int) ITriangles

Slice returns a sub-ITriangles of this GLTriangles in range [i, j).

func (*GLTriangles) Update

func (gt *GLTriangles) Update(t ITriangles)

Update copies vertex properties from the supplied ITriangles into this GLTriangles.

The two ITriangles (gt and t) must be of the same len.

func (*GLTriangles) VertexSlice

func (gt *GLTriangles) VertexSlice() *executor.VertexSlice

VertexSlice returns the VertexSlice of this GLTriangles.

You can use it to draw them.

type GLWindow

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

func NewGLWindow

func NewGLWindow(cfg WindowConfig) (*GLWindow, error)

func (*GLWindow) Bounds

func (w *GLWindow) Bounds() Rect

Bounds returns the current bounds of the GLWindow.

func (*GLWindow) Canvas

func (w *GLWindow) Canvas() *GLCanvas

GLCanvas returns the window's underlying GLCanvas

func (*GLWindow) Clear

func (w *GLWindow) Clear(c color.Color)

Clear clears the GLWindow with a single color.

func (*GLWindow) Clipboard

func (w *GLWindow) Clipboard() string

Clipboard returns the contents of the system clipboard.

func (*GLWindow) ClipboardText

func (w *GLWindow) ClipboardText() string

ClipboardText returns the current value of the systems clipboard.

func (*GLWindow) Closed

func (w *GLWindow) Closed() bool

Closed returns the closed flag of the GLWindow, which reports whether the GLWindow should be closed.

The closed flag is automatically set when a user attempts to close the GLWindow.

func (*GLWindow) Color

func (w *GLWindow) Color(at Vec) RGBA

Color returns the color of the pixel over the given position inside the GLWindow.

func (*GLWindow) CursorVisible

func (w *GLWindow) CursorVisible() bool

CursorVisible returns the visibility status of the mouse cursor.

func (*GLWindow) Destroy

func (w *GLWindow) Destroy()

Destroy destroys the GLWindow. The GLWindow can't be used any further.

func (*GLWindow) Focused

func (w *GLWindow) Focused() bool

Focused returns true if the GLWindow has input focus.

func (*GLWindow) GetPos

func (w *GLWindow) GetPos() Vec

GetPos gets the position, in screen coordinates, of the upper-left corner of the client area of the window. The position is rounded to integers.

func (*GLWindow) JoystickAxis

func (w *GLWindow) JoystickAxis(js Joystick, axis GamepadAxis) float64

JoystickAxis returns the value of a joystick axis at the last call to GLWindow.Update. If the axis index is out of range, this will return 0.

This API is experimental.

func (*GLWindow) JoystickAxisCount

func (w *GLWindow) JoystickAxisCount(js Joystick) int

JoystickAxisCount returns the number of axes a connected joystick has.

This API is experimental.

func (*GLWindow) JoystickButtonCount

func (w *GLWindow) JoystickButtonCount(js Joystick) int

JoystickButtonCount returns the number of buttons a connected joystick has.

This API is experimental.

func (*GLWindow) JoystickJustPressed

func (w *GLWindow) JoystickJustPressed(js Joystick, button GamepadButton) bool

JoystickJustPressed returns whether the joystick Button has just been pressed down. If the button index is out of range, this will return false.

This API is experimental.

func (*GLWindow) JoystickJustReleased

func (w *GLWindow) JoystickJustReleased(js Joystick, button GamepadButton) bool

JoystickJustReleased returns whether the joystick Button has just been released up. If the button index is out of range, this will return false.

This API is experimental.

func (*GLWindow) JoystickName

func (w *GLWindow) JoystickName(js Joystick) string

JoystickName returns the name of the joystick. A disconnected joystick will return an empty string.

This API is experimental.

func (*GLWindow) JoystickPresent

func (w *GLWindow) JoystickPresent(js Joystick) bool

JoystickPresent returns if the joystick is currently connected.

This API is experimental.

func (*GLWindow) JoystickPressed

func (w *GLWindow) JoystickPressed(js Joystick, button GamepadButton) bool

JoystickPressed returns whether the joystick Button is currently pressed down. If the button index is out of range, this will return false.

This API is experimental.

func (*GLWindow) JustPressed

func (w *GLWindow) JustPressed(button Button) bool

JustPressed returns whether the Button has been pressed in the last frame.

func (*GLWindow) JustReleased

func (w *GLWindow) JustReleased(button Button) bool

JustReleased returns whether the Button has been released in the last frame.

func (*GLWindow) KeysPressed

func (w *GLWindow) KeysPressed() map[Button]bool

func (*GLWindow) MakePicture

func (w *GLWindow) MakePicture(p IPicture) ITargetPicture

MakePicture generates a specialized copy of the supplied IPicture that will draw onto this GLWindow.

GLWindow supports IPictureColor.

func (*GLWindow) MakeTriangles

func (w *GLWindow) MakeTriangles(t ITriangles) ITargetTriangles

MakeTriangles generates a specialized copy of the supplied ITriangles that will draw onto this GLWindow.

GLWindow supports ITrianglesPosition, ITrianglesColor and ITrianglesPicture.

func (*GLWindow) Monitor

func (w *GLWindow) Monitor() *GLMonitor

GLMonitor returns a monitor the GLWindow is fullscreen on. If the GLWindow is not fullscreen, this function returns nil.

func (*GLWindow) MouseInsideWindow

func (w *GLWindow) MouseInsideWindow() bool

MouseInsideWindow returns true if the mouse position is within the GLWindow's Bounds.

func (*GLWindow) MousePosition

func (w *GLWindow) MousePosition() Vec

MousePosition returns the current mouse position in the GLWindow's Bounds.

func (*GLWindow) MousePreviousPosition

func (w *GLWindow) MousePreviousPosition() Vec

MousePreviousPosition returns the previous mouse position in the GLWindow's Bounds.

func (*GLWindow) MouseScroll

func (w *GLWindow) MouseScroll() Vec

MouseScroll returns the mouse scroll amount (in both axes) since the last call to GLWindow.Update.

func (*GLWindow) Pressed

func (w *GLWindow) Pressed(button Button) bool

func (*GLWindow) Repeated

func (w *GLWindow) Repeated(button Button) bool

Repeated returns whether a repeat event has been triggered on button.

Repeat event occurs repeatedly when a button is held down for some time.

func (*GLWindow) SetBounds

func (w *GLWindow) SetBounds(bounds Rect)

SetBounds sets the bounds of the GLWindow in pixels. Bounds can be fractional, but the actual size of the window will be rounded to integers.

func (*GLWindow) SetClipboard

func (w *GLWindow) SetClipboard(str string)

SetClipboardString sets the system clipboard to the specified UTF-8 encoded string.

func (*GLWindow) SetClipboardText

func (w *GLWindow) SetClipboardText(text string)

SetClipboardText passes the given string to the underlying glfw window to set the systems clipboard.

func (*GLWindow) SetClosed

func (w *GLWindow) SetClosed(closed bool)

SetClosed sets the closed flag of the GLWindow.

This is useful when overriding the user's attempt to close the GLWindow, or just to close the GLWindow from within the program.

func (*GLWindow) SetColorMask

func (w *GLWindow) SetColorMask(c color.Color)

SetColorMask sets a global color mask for the GLWindow.

func (*GLWindow) SetComposeMethod

func (w *GLWindow) SetComposeMethod(cmp ComposeMethod)

SetComposeMethod sets a Porter-Duff composition method to be used in the following draws onto this GLWindow.

func (*GLWindow) SetCursorDisabled

func (w *GLWindow) SetCursorDisabled()

SetCursorDisabled hides the cursor and provides unlimited virtual cursor movement make cursor visible using SetCursorVisible

func (*GLWindow) SetCursorVisible

func (w *GLWindow) SetCursorVisible(visible bool)

SetCursorVisible sets the visibility of the mouse cursor inside the GLWindow client area.

func (*GLWindow) SetMatrix

func (w *GLWindow) SetMatrix(m Matrix)

SetMatrix sets a Matrix that every point will be projected by.

func (*GLWindow) SetMonitor

func (w *GLWindow) SetMonitor(monitor *GLMonitor)

SetMonitor sets the GLWindow fullscreen on the given GLMonitor. If the GLMonitor is nil, the GLWindow will be restored to windowed state instead.

The GLWindow will be automatically set to the GLMonitor's resolution. If you want a different resolution, you will need to set it manually with SetBounds method.

func (*GLWindow) SetMousePosition

func (w *GLWindow) SetMousePosition(v Vec)

SetMousePosition positions the mouse cursor anywhere within the GLWindow's Bounds.

func (*GLWindow) SetPos

func (w *GLWindow) SetPos(pos Vec)

SetPos sets the position, in screen coordinates, of the upper-left corner of the client area of the window. Position can be fractional, but the actual position of the window will be rounded to integers.

If it is a full screen window, this function does nothing.

func (*GLWindow) SetSmooth

func (w *GLWindow) SetSmooth(smooth bool)

SetSmooth sets whether the stretched Pictures drawn onto this GLWindow should be drawn smooth or pixelated.

func (*GLWindow) SetTitle

func (w *GLWindow) SetTitle(title string)

SetTitle changes the title of the GLWindow.

func (*GLWindow) SetVSync

func (w *GLWindow) SetVSync(vsync bool)

SetVSync sets whether the GLWindow's Update should synchronize with the monitor refresh rate.

func (*GLWindow) Show

func (w *GLWindow) Show()

Show makes the window visible, if it was previously hidden. If the window is already visible or is in full screen mode, this function does nothing.

func (*GLWindow) Smooth

func (w *GLWindow) Smooth() bool

Smooth returns whether the stretched Pictures drawn onto this GLWindow are set to be drawn smooth or pixelated.

func (*GLWindow) SwapBuffers

func (w *GLWindow) SwapBuffers()

SwapBuffers swaps buffers. Call this to swap buffers without polling window events. Note that Update invokes SwapBuffers.

func (*GLWindow) Typed

func (w *GLWindow) Typed() string

Typed returns the text typed on the keyboard since the last call to GLWindow.Update.

func (*GLWindow) Update

func (w *GLWindow) Update()

Update swaps buffers and polls events. Call this method at the end of each frame.

func (*GLWindow) UpdateInput

func (w *GLWindow) UpdateInput()

UpdateInput polls window events. Call this function to poll window events without swapping buffers. Note that the Update method invokes UpdateInput.

func (*GLWindow) UpdateInputWait

func (w *GLWindow) UpdateInputWait(timeout time.Duration)

UpdateInputWait blocks until an event is received or a timeout. If timeout is 0 then it will wait indefinitely

func (*GLWindow) VSync

func (w *GLWindow) VSync() bool

VSync returns whether the GLWindow is set to synchronize with the monitor refresh rate.

type GamepadAxis

type GamepadAxis int

GamepadAxis corresponds to a gamepad axis.

type GamepadButton

type GamepadButton int

GamepadButton corresponds to a gamepad button.

type Glyph

type Glyph struct {
	Dot     Vec
	Frame   Rect
	Advance float64
}

Glyph describes one glyph in an Atlas.

type IBasicTarget

type IBasicTarget interface {
	ITarget

	// SetMatrix sets a Matrix that every point will be projected by.
	SetMatrix(Matrix)

	// SetColorMask sets a color that will be multiplied with the ITrianglesColor property of all
	// ITriangles.
	SetColorMask(color.Color)
}

IBasicTarget is a ITarget with additional basic adjustment methods.

type IMDraw

type IMDraw struct {
	Color     color.Color
	Picture   Vec
	Intensity float64
	Precision int
	EndShape  EndShape
	// contains filtered or unexported fields
}

func NewIMDraw

func NewIMDraw(pic IPicture) *IMDraw

func (*IMDraw) Circle

func (imd *IMDraw) Circle(radius, thickness float64)

Circle draws a circle of the specified radius around each Pushed point. If the thickness is 0, the circle will be filled, otherwise a circle outline of the specified thickness will be drawn.

func (*IMDraw) CircleArc

func (imd *IMDraw) CircleArc(radius, low, high, thickness float64)

CircleArc draws a circle arc of the specified radius around each Pushed point. If the thickness is 0, the arc will be filled, otherwise will be outlined. The arc starts at the low angle and continues to the high angle. If low<high, the arc will be drawn counterclockwise. Otherwise it will be clockwise. The angles are not normalized by any means.

imd.CircleArc(40, 0, 8*math.Pi, 0)

This line will fill the whole circle 4 times.

func (*IMDraw) Clear

func (imd *IMDraw) Clear()

func (*IMDraw) Draw

func (imd *IMDraw) Draw(t ITarget)

Draw draws all currently drawn shapes inside the IM onto another ITarget.

Note, that IMDraw's matrix and color mask have no effect here.

func (*IMDraw) Ellipse

func (imd *IMDraw) Ellipse(radius Vec, thickness float64)

Ellipse draws an ellipse of the specified radius in each axis around each Pushed points. If the thickness is 0, the ellipse will be filled, otherwise an ellipse outline of the specified thickness will be drawn.

func (*IMDraw) EllipseArc

func (imd *IMDraw) EllipseArc(radius Vec, low, high, thickness float64)

EllipseArc draws an ellipse arc of the specified radius in each axis around each Pushed point. If the thickness is 0, the arc will be filled, otherwise will be outlined. The arc starts at the low angle and continues to the high angle. If low<high, the arc will be drawn counterclockwise. Otherwise it will be clockwise. The angles are not normalized by any means.

imd.EllipseArc(pixel.V(100, 50), 0, 8*math.Pi, 0)

This line will fill the whole ellipse 4 times.

func (*IMDraw) Line

func (imd *IMDraw) Line(thickness float64)

Line draws a polyline of the specified thickness between the Pushed points.

func (*IMDraw) MakePicture

func (imd *IMDraw) MakePicture(p IPicture) ITargetPicture

MakePicture returns a specialized copy of the provided IPicture that draws onto this IMDraw.

func (*IMDraw) MakeTriangles

func (imd *IMDraw) MakeTriangles(t ITriangles) ITargetTriangles

MakeTriangles returns a specialized copy of the provided ITriangles that draws onto this IMDraw.

func (*IMDraw) Polygon

func (imd *IMDraw) Polygon(thickness float64)

Polygon draws a polygon from the Pushed points. If the thickness is 0, the convex polygon will be filled. Otherwise, an outline of the specified thickness will be drawn. The outline does not have to be convex.

Note, that the filled polygon does not have to be strictly convex. The way it's drawn is that a triangle is drawn between each two adjacent points and the first Pushed point. You can use this property to draw certain kinds of concave polygons.

func (*IMDraw) Push

func (imd *IMDraw) Push(pts ...Vec)

Push adds some points to the IM queue. All Pushed points will have the same properties except for the position.

func (*IMDraw) Rectangle

func (imd *IMDraw) Rectangle(thickness float64)

Rectangle draws a rectangle between each two subsequent Pushed points. Drawing a rectangle between two points means drawing a rectangle with sides parallel to the axes of the coordinate system, where the two points specify it's two opposite corners.

If the thickness is 0, rectangles will be filled, otherwise will be outlined with the given thickness.

func (*IMDraw) Reset

func (imd *IMDraw) Reset()

Reset restores all point properties to defaults and removes all Pushed points.

This does not affect matrix and color mask set by SetMatrix and SetColorMask.

func (*IMDraw) SetColorMask

func (imd *IMDraw) SetColorMask(color color.Color)

SetColorMask sets a color that all further point's color will be multiplied by.

func (*IMDraw) SetMatrix

func (imd *IMDraw) SetMatrix(m Matrix)

SetMatrix sets a Matrix that all further points will be transformed by.

type IPicture

type IPicture interface {
	// Bounds returns the rectangle of the IPicture. All data is located with this rectangle.
	// Querying properties outside the rectangle should return default value of that property.
	Bounds() Rect
}

IPicture represents a rectangular area of raster data, such as a color. It has Bounds which specify the rectangle where data is located.

type IPictureColor

type IPictureColor interface {
	IPicture
	Color(at Vec) RGBA
}

IPictureColor specifies IPicture with Color property, so that every position inside the IPicture's Bounds has a color.

Positions outside the IPicture's Bounds must return full transparent (Alpha(0)).

type ITarget

type ITarget interface {
	// MakeTriangles generates a specialized copy of the provided ITriangles.
	//
	// When calling Draw method on the returned ITargetTriangles, the ITargetTriangles will be
	// drawn onto the ITarget that generated them.
	//
	// Note, that not every ITarget has to recognize all possible types of ITriangles. Some may
	// only recognize ITrianglesPosition and ITrianglesColor and ignore all other properties (if
	// present) when making new ITargetTriangles. This varies from ITarget to ITarget.
	MakeTriangles(ITriangles) ITargetTriangles

	// MakePicture generates a specialized copy of the provided IPicture.
	//
	// When calling Draw method on the returned ITargetPicture, the ITargetPicture will be drawn
	// onto the ITarget that generated it together with the ITargetTriangles supplied to the Draw
	// method.
	MakePicture(IPicture) ITargetPicture
}

ITarget is something that can be drawn onto, such as a window, a canvas, and so on.

You can notice, that there are no "drawing" methods in a ITarget. That's because all drawing happens indirectly through ITriangles and IPicture instances generated via MakeTriangles and MakePicture method.

type ITargetPicture

type ITargetPicture interface {
	IPicture

	// Draw draws the supplied ITargetTriangles (which must be generated by the same ITarget as
	// this ITargetPicture) with this ITargetPicture. The ITargetTriangles should utilize the data
	// from this ITargetPicture in some way.
	Draw(ITargetTriangles)

	Update(p IPicture)
}

ITargetPicture is a IPicture generated by a ITarget using MakePicture method. This IPicture can be drawn onto that (no other) ITarget together with a ITargetTriangles generated by the same ITarget.

The ITargetTriangles specify where, shape and how the IPicture should be drawn.

type ITargetTriangles

type ITargetTriangles interface {
	ITriangles

	// Draw draws ITriangles onto an associated ITarget.
	Draw()
}

ITargetTriangles are ITriangles generated by a ITarget with MakeTriangles method. They can be drawn onto that (no other) ITarget.

type ITriangles

type ITriangles interface {
	// Len returns the number of vertices. The number of triangles is the number of vertices
	// divided by 3.
	Len() int

	// SetLen resizes ITriangles to len vertices. If ITriangles B were obtained by calling Slice
	// method on ITriangles A, the relationship between A and B is undefined after calling SetLen
	// on either one of them.
	SetLen(len int)

	// Slice returns a sub-ITriangles of this ITriangles, covering vertices in range [i, j).
	//
	// If ITriangles B were obtained by calling Slice(4, 9) on ITriangles A, then A and B must
	// share the same underlying data. Modifying B must change the contents of A in range
	// [4, 9). The vertex with index 0 at B is the vertex with index 4 in A, and so on.
	//
	// Returned ITriangles must have the same underlying type.
	Slice(i, j int) ITriangles

	// Update copies vertex properties from the supplied ITriangles into this ITriangles.
	//
	// Properties not supported by these ITriangles should be ignored. Properties not supported by
	// the supplied ITriangles should be left untouched.
	//
	// The two ITriangles must have the same Len.
	Update(ITriangles)

	// Copy creates an exact independent copy of this ITriangles (with the same underlying type).
	Copy() ITriangles
}

ITriangles represents a list of vertices, where each three vertices form a triangle. (First, second and third is the first triangle, fourth, fifth and sixth is the second triangle, etc.)

type ITrianglesClipped

type ITrianglesClipped interface {
	ITriangles
	ClipRect(i int) (rect Rect, is bool)
}

ITrianglesClipped specifies ITriangles with Clipping Rectangle property.

The first value returned from ClipRect method is the clipping rectangle. The second one specifies if the triangle is clipped.

type ITrianglesColor

type ITrianglesColor interface {
	ITriangles
	Color(i int) RGBA
}

ITrianglesColor specifies ITriangles with Color property.

type ITrianglesPicture

type ITrianglesPicture interface {
	ITriangles
	Picture(i int) (pic Vec, intensity float64)
}

ITrianglesPicture specifies ITriangles with IPicture property.

The first value returned from IPicture method is IPicture coordinates. The second one specifies the weight of the IPicture. Value of 0 means, that IPicture should be completely ignored, 1 means that is should be fully included and anything in between means anything in between.

type ITrianglesPosition

type ITrianglesPosition interface {
	ITriangles
	Position(i int) Vec
}

ITrianglesPosition specifies ITriangles with Position property.

type Joystick

type Joystick int

Joystick is a joystick or controller (gamepad).

type Line

type Line struct {
	A, B Vec
}

Line is a 2D line segment, between points A and B.

func L

func L(from, to Vec) Line

L creates and returns a new Line.

func (Line) Bounds

func (l Line) Bounds() Rect

Bounds returns the lines bounding box. This is in the form of a normalized Rect.

func (Line) Center

func (l Line) Center() Vec

Center will return the point at center of the line; that is, the point equidistant from either end.

func (Line) Closest

func (l Line) Closest(v Vec) Vec

Closest will return the point on the line which is closest to the Vec provided.

func (Line) Contains

func (l Line) Contains(v Vec) bool

Contains returns whether the provided Vec lies on the line.

func (Line) Formula

func (l Line) Formula() (m, b float64)

Formula will return the values that represent the line in the formula: y = mx + b This function will return math.Inf+, math.Inf- for a vertical line.

func (Line) Intersect

func (l Line) Intersect(k Line) (Vec, bool)

Intersect will return the point of intersection for the two line segments. If the line segments do not intersect, this function will return the zero-vector and false.

func (Line) IntersectCircle

func (l Line) IntersectCircle(c Circle) Vec

IntersectCircle will return the shortest Vec such that moving the Line by that Vec will cause the Line and Circle to no longer intesect. If they do not intersect at all, this function will return a zero-vector.

func (Line) IntersectRect

func (l Line) IntersectRect(r Rect) Vec

IntersectRect will return the shortest Vec such that moving the Line by that Vec will cause the Line and Rect to no longer intesect. If they do not intersect at all, this function will return a zero-vector.

func (Line) Len

func (l Line) Len() float64

Len returns the length of the line segment.

func (Line) Moved

func (l Line) Moved(delta Vec) Line

Moved will return a line moved by the delta Vec provided.

func (Line) Rotated

func (l Line) Rotated(around Vec, angle float64) Line

Rotated will rotate the line around the provided Vec.

func (Line) Scaled

func (l Line) Scaled(scale float64) Line

Scaled will return the line scaled around the center point.

func (Line) ScaledXY

func (l Line) ScaledXY(around Vec, scale float64) Line

ScaledXY will return the line scaled around the Vec provided.

func (Line) String

func (l Line) String() string

type Matrix

type Matrix [6]float64

Matrix is a 2x3 affine matrix that can be used for all kinds of spatial transforms, such as movement, scaling and rotations.

Matrix has a handful of useful methods, each of which adds a transformation to the matrix. For example:

pixel.IM.Moved(pixel.V(100, 200)).Rotated(pixel.ZV, math.Pi/2)

This code creates a Matrix that first moves everything by 100 units horizontally and 200 units vertically and then rotates everything by 90 degrees around the origin.

Layout is: [0] [2] [4] [1] [3] [5]

0   0   1  (implicit row)

func (Matrix) Chained

func (m Matrix) Chained(next Matrix) Matrix

Chained adds another Matrix to this one. All tranformations by the next Matrix will be applied after the transformations of this Matrix.

func (Matrix) Moved

func (m Matrix) Moved(delta Vec) Matrix

Moved moves everything by the delta vector.

func (Matrix) Project

func (m Matrix) Project(u Vec) Vec

Project applies all transformations added to the Matrix to a vector u and returns the result.

Time complexity is O(1).

func (Matrix) Rotated

func (m Matrix) Rotated(around Vec, angle float64) Matrix

Rotated rotates everything around a given point by the given angle in radians.

func (Matrix) Scaled

func (m Matrix) Scaled(around Vec, scale float64) Matrix

Scaled scales everything around a given point by the scale factor.

func (Matrix) ScaledXY

func (m Matrix) ScaledXY(around Vec, scale Vec) Matrix

ScaledXY scales everything around a given point by the scale factor in each axis respectively.

func (Matrix) String

func (m Matrix) String() string

String returns a string representation of the Matrix.

m := pixel.IM
fmt.Println(m) // Matrix(1 0 0 | 0 1 0)

func (Matrix) Unproject

func (m Matrix) Unproject(u Vec) Vec

Unproject does the inverse operation to Project.

Time complexity is O(1).

type PictureRGBA

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

func NewPictureRGBA

func NewPictureRGBA(rect Rect) *PictureRGBA

func NewPictureRGBAFromImage

func NewPictureRGBAFromImage(img image.Image) *PictureRGBA

func NewPictureRGBAFromPicture

func NewPictureRGBAFromPicture(pic IPicture) *PictureRGBA

func (*PictureRGBA) Bounds

func (s *PictureRGBA) Bounds() Rect

func (*PictureRGBA) Image

func (s *PictureRGBA) Image() *image.RGBA

func (*PictureRGBA) Pixels

func (s *PictureRGBA) Pixels() []uint8

func (*PictureRGBA) SetColor

func (s *PictureRGBA) SetColor(x int, y int, c color.RGBA)

func (*PictureRGBA) SetRGBA

func (s *PictureRGBA) SetRGBA(x int, y int, r uint8, g uint8, b uint8, a uint8)

func (*PictureRGBA) SetRGBASize

func (s *PictureRGBA) SetRGBASize(x int, y int, r uint8, g uint8, b uint8, a uint8, size int)

type RGBA

type RGBA struct {
	R, G, B, A float64
}

RGBA represents an alpha-premultiplied RGBA color with components within range [0, 1].

The difference between color.RGBA is that the value range is [0, 1] and the values are floats.

func Alpha

func Alpha(a float64) RGBA

Alpha returns a white RGBA color with the given alpha component.

func RGB

func RGB(r, g, b float64) RGBA

RGB returns a fully opaque RGBA color with the given RGB values.

A common way to construct a transparent color is to create one with RGB constructor, then multiply it by a color obtained from the Alpha constructor.

func ToRGBA

func ToRGBA(c color.Color) RGBA

ToRGBA converts a color to RGBA format. Using this function is preferred to using RGBAModel, for performance (using RGBAModel introduces additional unnecessary allocations).

func (RGBA) Add

func (c RGBA) Add(d RGBA) RGBA

Add adds color d to color c component-wise and returns the result (the components are not clamped).

func (RGBA) Mul

func (c RGBA) Mul(d RGBA) RGBA

Mul multiplies color c by color d component-wise (the components are not clamped).

func (RGBA) RGBA

func (c RGBA) RGBA() (r, g, b, a uint32)

RGBA returns alpha-premultiplied red, green, blue and alpha components of the RGBA color.

func (RGBA) Scaled

func (c RGBA) Scaled(scale float64) RGBA

Scaled multiplies each component of color c by scale and returns the result (the components are not clamped).

func (RGBA) Sub

func (c RGBA) Sub(d RGBA) RGBA

Sub subtracts color d from color c component-wise and returns the result (the components are not clamped).

type Rect

type Rect struct {
	Min Vec
	Max Vec
}

Rect is a 2D rectangle aligned with the axes of the coordinate system. It is defined by two points, Min and Max.

The invariant should hold, that Max's components are greater or equal than Min's components respectively.

func R

func R(minX, minY, maxX, maxY float64) Rect

R returns a new Rect with given the Min and Max coordinates.

Note that the returned rectangle is not automatically normalized.

func (Rect) AlignedTo

func (r Rect) AlignedTo(anchor Anchor) Rect

AlignedTo returns the rect moved by the given anchor.

func (Rect) AnchorPos

func (r Rect) AnchorPos(anchor Anchor) Vec

AnchorPos returns the relative position of the given anchor.

func (Rect) Area

func (r Rect) Area() float64

Area returns the area of r. If r is not normalized, area may be negative.

func (Rect) Center

func (r Rect) Center() Vec

Center returns the position of the center of the Rect. `rect.Center()` is equivalent to `rect.Anchor(pixel.Anchor.Center)`

func (Rect) Contains

func (r Rect) Contains(u Vec) bool

Contains checks whether a vector u is contained within this Rect (including it's borders).

func (Rect) Edges

func (r Rect) Edges() [4]Line

Edges will return the four lines which make up the edges of the rectangle.

func (Rect) H

func (r Rect) H() float64

H returns the height of the Rect.

func (Rect) Intersect

func (r Rect) Intersect(s Rect) Rect

Intersect returns the maximal Rect which is covered by both r and s. Rects r and s must be normalized.

If r and s don't overlap, this function returns a zero-rectangle.

func (Rect) IntersectCircle

func (r Rect) IntersectCircle(c Circle) Vec

IntersectCircle returns a minimal required Vector, such that moving the rect by that vector would stop the Circle and the Rect intersecting. This function returns a zero-vector if the Circle and Rect do not overlap, and if only the perimeters touch.

This function will return a non-zero vector if:

  • The Rect contains the Circle, partially or fully
  • The Circle contains the Rect, partially of fully

func (Rect) IntersectLine

func (r Rect) IntersectLine(l Line) Vec

IntersectLine will return the shortest Vec such that if the Rect is moved by the Vec returned, the Line and Rect no longer intersect.

func (Rect) IntersectionPoints

func (r Rect) IntersectionPoints(l Line) []Vec

IntersectionPoints returns all the points where the Rect intersects with the line provided. This can be zero, one or two points, depending on the location of the shapes. The points of intersection will be returned in order of closest-to-l.A to closest-to-l.B.

func (Rect) Intersects

func (r Rect) Intersects(s Rect) bool

Intersects returns whether or not the given Rect intersects at any point with this Rect.

This function is overall about 5x faster than Intersect, so it is better to use if you have no need for the returned Rect from Intersect.

func (Rect) Moved

func (r Rect) Moved(delta Vec) Rect

Moved returns the Rect moved (both Min and Max) by the given vector delta.

func (Rect) Norm

func (r Rect) Norm() Rect

Norm returns the Rect in normal form, such that Max is component-wise greater or equal than Min.

func (Rect) Resized

func (r Rect) Resized(anchor, size Vec) Rect

Resized returns the Rect resized to the given size while keeping the position of the given anchor.

r.Resized(r.Min, size)      // resizes while keeping the position of the lower-left corner
r.Resized(r.Max, size)      // same with the top-right corner
r.Resized(r.Center(), size) // resizes around the center

This function does not make sense for resizing a rectangle of zero area and will panic. Use ResizedMin in the case of zero area.

func (Rect) ResizedMin

func (r Rect) ResizedMin(size Vec) Rect

ResizedMin returns the Rect resized to the given size while keeping the position of the Rect's Min.

Sizes of zero area are safe here.

func (Rect) Size

func (r Rect) Size() Vec

Size returns the vector of width and height of the Rect.

func (Rect) String

func (r Rect) String() string

String returns the string representation of the Rect.

r := pixel.R(100, 50, 200, 300)
r.String()     // returns "Rect(100, 50, 200, 300)"
fmt.Println(r) // Rect(100, 50, 200, 300)

func (Rect) Union

func (r Rect) Union(s Rect) Rect

Union returns the minimal Rect which covers both r and s. Rects r and s must be normalized.

func (Rect) Vertices

func (r Rect) Vertices() [4]Vec

Vertices returns a slice of the four corners which make up the rectangle.

func (Rect) W

func (r Rect) W() float64

W returns the width of the Rect.

type Sprite

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

func NewSprite

func NewSprite() *Sprite

func NewSpriteFromPicture

func NewSpriteFromPicture(pic IPicture, frame Rect) *Sprite

func (*Sprite) Draw

func (s *Sprite) Draw(t ITarget, matrix Matrix)

func (*Sprite) DrawColorMask

func (s *Sprite) DrawColorMask(t ITarget, matrix Matrix, mask color.Color)

func (*Sprite) Frame

func (s *Sprite) Frame() Rect

func (*Sprite) Picture

func (s *Sprite) Picture() IPicture

func (*Sprite) Set

func (s *Sprite) Set(pic IPicture, frame Rect)

func (*Sprite) SetCached

func (s *Sprite) SetCached(cached CacheMode)

type Text

type Text struct {
	// Orig specifies the text origin, usually the top-left dot position. Dot is always aligned
	// to Orig when writing newlines.
	Orig Vec

	// Dot is the position where the next character will be written. Dot is automatically moved
	// when writing to a Text object, but you can also manipulate it manually
	Dot Vec

	// Color is the color of the text that is to be written. Defaults to white.
	Color color.Color

	// LineHeight is the vertical distance between two lines of text.
	//
	// Example:
	//   txt.LineHeight = 1.5 * txt.Atlas().LineHeight()
	LineHeight float64

	// TabWidth is the horizontal tab width. Tab characters will align to the multiples of this
	// width.
	//
	// Example:
	//   txt.TabWidth = 8 * txt.Atlas().Glyph(' ').Advance
	TabWidth float64
	// contains filtered or unexported fields
}

Text allows for effiecient and convenient text drawing.

To create a Text object, use the New constructor:

txt := text.New(pixel.ZV, text.NewAtlas(face, text.ASCII))

As suggested by the constructor, a Text object is always associated with one font face and a fixed set of runes. For example, the Text we created above can draw text using the font face contained in the face variable and is capable of drawing ASCII characters.

Here we create a Text object which can draw ASCII and Katakana characters:

txt := text.New(0, text.NewAtlas(face, text.ASCII, text.RangeTable(unicode.Katakana)))

Similarly to IMDraw, Text functions as a buffer. It implements io.Writer interface, so writing text to it is really simple:

fmt.Print(txt, "Hello, world!")

Newlines, tabs and carriage returns are supported.

Finally, if we want the written text to show up on some other ITarget, we can draw it:

txt.Draw(target)

Text exports two important fields: Orig and Dot. Dot is the position where the next character will be written. Dot is automatically moved when writing to a Text object, but you can also manipulate it manually. Orig specifies the text origin, usually the top-left dot position. Dot is always aligned to Orig when writing newlines. The Clear method resets the Dot to Orig.

func NewText

func NewText(orig Vec, atlas *Atlas) *Text

New creates a new Text capable of drawing runes contained in the provided Atlas. Orig and Dot will be initially set to orig.

Here we create a Text capable of drawing ASCII characters using the Go Regular font.

ttf, err := truetype.Parse(goregular.TTF)
if err != nil {
    panic(err)
}
face := truetype.NewFace(ttf, &truetype.Options{
    Size: 14,
})
txt := text.New(orig, text.NewAtlas(face, text.ASCII))

func (*Text) AlignedTo

func (txt *Text) AlignedTo(anchor Anchor) *Text

AlignedTo returns the text moved by the given anchor.

func (*Text) Atlas

func (txt *Text) Atlas() *Atlas

Atlas returns the underlying Text's Atlas containing all of the pre-drawn glyphs. The Atlas is also useful for getting values such as the recommended line height.

func (*Text) Bounds

func (txt *Text) Bounds() Rect

Bounds returns the bounding box of the text currently written to the Text excluding whitespace.

If the Text is empty, a zero rectangle is returned.

func (*Text) BoundsOf

func (txt *Text) BoundsOf(s string) Rect

BoundsOf returns the bounding box of s if it was to be written to the Text right now.

func (*Text) Clear

func (txt *Text) Clear()

Clear removes all written text from the Text. The Dot field is reset to Orig.

func (*Text) Draw

func (txt *Text) Draw(t ITarget, matrix Matrix)

Draw draws all text written to the Text to the provided ITarget. The text is transformed by the provided Matrix.

This method is equivalent to calling DrawColorMask with nil color mask.

If there's a lot of text written to the Text, changing a matrix or a color mask often might hurt performance. Consider using your ITarget's SetMatrix or SetColorMask methods if available.

func (*Text) DrawColorMask

func (txt *Text) DrawColorMask(t ITarget, matrix Matrix, mask color.Color)

DrawColorMask draws all text written to the Text to the provided ITarget. The text is transformed by the provided Matrix and masked by the provided color mask.

If there's a lot of text written to the Text, changing a matrix or a color mask often might hurt performance. Consider using your ITarget's SetMatrix or SetColorMask methods if available.

func (*Text) Write

func (txt *Text) Write(p []byte) (n int, err error)

Write writes a slice of bytes to the Text. This method never fails, always returns len(p), nil.

func (*Text) WriteByte

func (txt *Text) WriteByte(c byte) error

WriteByte writes a byte to the Text. This method never fails, always returns nil.

Writing a multi-byte rune byte-by-byte is perfectly supported.

func (*Text) WriteRune

func (txt *Text) WriteRune(r rune) (n int, err error)

WriteRune writes a rune to the Text. This method never fails, always returns utf8.RuneLen(r), nil.

func (*Text) WriteString

func (txt *Text) WriteString(s string) (n int, err error)

WriteString writes a string to the Text. This method never fails, always returns len(s), nil.

type TriangleData

type TriangleData struct {
	Position  Vec
	Color     RGBA
	Picture   Vec
	Intensity float64
	ClipRect  Rect
	IsClipped bool
}

type TrianglesData

type TrianglesData []TriangleData

TrianglesData specifies a list of ITriangles vertices with three common properties: ITrianglesPosition, ITrianglesColor and ITrianglesPicture.

func MakeTrianglesData

func MakeTrianglesData(len int) *TrianglesData

MakeTrianglesData creates TrianglesData of length len initialized with default property values.

Prefer this function to make(TrianglesData, len), because make zeros them, while this function does the correct initialization.

func (*TrianglesData) ClipRect

func (td *TrianglesData) ClipRect(i int) (rect Rect, has bool)

ClipRect returns the clipping rectangle property of the i-th vertex.

func (*TrianglesData) Color

func (td *TrianglesData) Color(i int) RGBA

Color returns the color property of i-th vertex.

func (*TrianglesData) Copy

func (td *TrianglesData) Copy() ITriangles

Copy returns an exact independent copy of this TrianglesData.

func (*TrianglesData) Len

func (td *TrianglesData) Len() int

Len returns the number of vertices in TrianglesData.

func (*TrianglesData) Picture

func (td *TrianglesData) Picture(i int) (pic Vec, intensity float64)

IPicture returns the picture property of i-th vertex.

func (*TrianglesData) Position

func (td *TrianglesData) Position(i int) Vec

Position returns the position property of i-th vertex.

func (*TrianglesData) SetLen

func (td *TrianglesData) SetLen(len int)

SetLen resizes TrianglesData to len, while keeping the original content.

If len is greater than TrianglesData's current length, the new data is filled with default values ((0, 0), white, (0, 0), 0).

func (*TrianglesData) Slice

func (td *TrianglesData) Slice(i, j int) ITriangles

Slice returns a sub-ITriangles of this TrianglesData.

func (*TrianglesData) Update

func (td *TrianglesData) Update(t ITriangles)

Update copies vertex properties from the supplied ITriangles into this TrianglesData.

ITrianglesPosition, ITrianglesColor and TrianglesTexture are supported.

type Vec

type Vec struct {
	X, Y float64
}

Vec is a 2D vector type with X and Y coordinates.

Create vectors with the V constructor:

u := pixel.V(1, 2)
v := pixel.V(8, -3)

Use various methods to manipulate them:

  w := u.Add(v)
  fmt.Println(w)        // Vec(9, -1)
  fmt.Println(u.Sub(v)) // Vec(-7, 5)
  u = pixel.V(2, 3)
  v = pixel.V(8, 1)
  if u.X < 0 {
	     fmt.Println("this won't happen")
  }
  x := u.Unit().Dot(v.Unit())

func Lerp

func Lerp(a, b Vec, t float64) Vec

Lerp returns a linear interpolation between vectors a and b.

This function basically returns a point along the line between a and b and t chooses which one. If t is 0, then a will be returned, if t is 1, b will be returned. Anything between 0 and 1 will return the appropriate point between a and b and so on.

func MakeVec

func MakeVec(x float64, y float64) Vec

V returns a new 2D vector with the given coordinates.

func Unit

func Unit(angle float64) Vec

Unit returns a vector of length 1 facing the given angle.

func (Vec) Add

func (u Vec) Add(v Vec) Vec

Add returns the sum of vectors u and v.

func (Vec) Angle

func (u Vec) Angle() float64

Angle returns the angle between the vector u and the x-axis. The result is in range [-Pi, Pi].

func (Vec) Cross

func (u Vec) Cross(v Vec) float64

Cross return the cross product of vectors u and v.

func (Vec) Dot

func (u Vec) Dot(v Vec) float64

Dot returns the dot product of vectors u and v.

func (Vec) Eq

func (u Vec) Eq(v Vec) bool

Eq will compare two vectors and return whether they are equal accounting for rounding errors. At worst, the result is correct to 7 significant digits.

func (Vec) Floor

func (u Vec) Floor() Vec

Floor converts x and y to their integer equivalents.

func (Vec) Len

func (u Vec) Len() float64

Len returns the length of the vector u.

func (Vec) Map

func (u Vec) Map(f func(float64) float64) Vec

Map applies the function f to both x and y components of the vector u and returns the modified vector.

u := pixel.V(10.5, -1.5)
v := u.Map(math.Floor)   // v is Vec(10, -2), both components of u floored

func (Vec) Normal

func (u Vec) Normal() Vec

Normal returns a vector normal to u. Equivalent to u.Rotated(math.Pi / 2), but faster.

func (Vec) Project

func (u Vec) Project(v Vec) Vec

Project returns a projection (or component) of vector u in the direction of vector v.

Behaviour is undefined if v is a zero vector.

func (Vec) Rotated

func (u Vec) Rotated(angle float64) Vec

Rotated returns the vector u rotated by the given angle in radians.

func (Vec) Scaled

func (u Vec) Scaled(c float64) Vec

Scaled returns the vector u multiplied by c.

func (Vec) ScaledXY

func (u Vec) ScaledXY(v Vec) Vec

ScaledXY returns the vector u multiplied by the vector v component-wise.

func (Vec) String

func (u Vec) String() string

String returns the string representation of the vector u.

u := pixel.V(4.5, -1.3)
u.String()     // returns "Vec(4.5, -1.3)"
fmt.Println(u) // Vec(4.5, -1.3)

func (Vec) Sub

func (u Vec) Sub(v Vec) Vec

Sub returns the difference betweeen vectors u and v.

func (Vec) To

func (u Vec) To(v Vec) Vec

To returns the vector from u to v. Equivalent to v.Sub(u).

func (Vec) Unit

func (u Vec) Unit() Vec

Unit returns a vector of length 1 facing the direction of u (has the same angle).

func (Vec) XY

func (u Vec) XY() (x, y float64)

XY returns the components of the vector in two return values.

type VideoMode

type VideoMode struct {
	// Width is the width of the vide mode in pixels.
	Width int
	// Height is the height of the video mode in pixels.
	Height int
	// RefreshRate holds the refresh rate of the associated monitor in Hz.
	RefreshRate int
}

VideoMode represents all properties of a video mode and is associated with a monitor if it is used in fullscreen mode.

type WindowConfig

type WindowConfig struct {
	Title string

	Icon []IPicture

	Bounds Rect

	Position Vec

	Monitor *GLMonitor

	Smooth bool

	Resizable bool

	Undecorated bool

	NoIconify bool

	AlwaysOnTop bool

	TransparentFramebuffer bool

	VSync bool

	Maximized bool

	Invisible bool

	SamplesMSAA int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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