Documentation ¶
Overview ¶
Package pixelgl implements efficient OpenGL targets and utilities for the Pixel game development library, specifically Window and Canvas.
It also contains a few additional utilities to help extend Pixel with OpenGL graphical effects.
Index ¶
- Constants
- func Run(run func())
- type Button
- type Canvas
- func (c *Canvas) Bounds() pixel.Rect
- func (c *Canvas) Clear(color color.Color)
- func (c *Canvas) Color(at pixel.Vec) pixel.RGBA
- func (c *Canvas) Draw(t pixel.Target, matrix pixel.Matrix)
- func (c *Canvas) DrawColorMask(t pixel.Target, matrix pixel.Matrix, mask color.Color)
- func (c *Canvas) Frame() *glhf.Frame
- func (c *Canvas) MakePicture(p pixel.Picture) pixel.TargetPicture
- func (c *Canvas) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles
- func (c *Canvas) Pixels() []uint8
- func (c *Canvas) SetBounds(bounds pixel.Rect)
- func (c *Canvas) SetColorMask(col color.Color)
- func (c *Canvas) SetComposeMethod(cmp pixel.ComposeMethod)
- func (c *Canvas) SetMatrix(m pixel.Matrix)
- func (c *Canvas) SetPixels(pixels []uint8)
- func (c *Canvas) SetSmooth(smooth bool)
- func (c *Canvas) Smooth() bool
- func (c *Canvas) Texture() *glhf.Texture
- type GLFrame
- type GLPicture
- type GLTriangles
- func (gt *GLTriangles) Color(i int) pixel.RGBA
- func (gt *GLTriangles) Copy() pixel.Triangles
- func (gt *GLTriangles) Len() int
- func (gt *GLTriangles) Picture(i int) (pic pixel.Vec, intensity float64)
- func (gt *GLTriangles) Position(i int) pixel.Vec
- func (gt *GLTriangles) SetLen(len int)
- func (gt *GLTriangles) Shader() *glhf.Shader
- func (gt *GLTriangles) Slice(i, j int) pixel.Triangles
- func (gt *GLTriangles) Update(t pixel.Triangles)
- func (gt *GLTriangles) VertexSlice() *glhf.VertexSlice
- type Monitor
- type Window
- func (w *Window) Bounds() pixel.Rect
- func (w *Window) Clear(c color.Color)
- func (w *Window) Closed() bool
- func (w *Window) Color(at pixel.Vec) pixel.RGBA
- func (w *Window) CursorVisible() bool
- func (w *Window) Destroy()
- func (w *Window) Focused() bool
- func (w *Window) JustPressed(button Button) bool
- func (w *Window) JustReleased(button Button) bool
- func (w *Window) MakePicture(p pixel.Picture) pixel.TargetPicture
- func (w *Window) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles
- func (w *Window) Monitor() *Monitor
- func (w *Window) MousePosition() pixel.Vec
- func (w *Window) MouseScroll() pixel.Vec
- func (w *Window) Pressed(button Button) bool
- func (w *Window) Repeated(button Button) bool
- func (w *Window) SetBounds(bounds pixel.Rect)
- func (w *Window) SetClosed(closed bool)
- func (w *Window) SetColorMask(c color.Color)
- func (w *Window) SetComposeMethod(cmp pixel.ComposeMethod)
- func (w *Window) SetCursorVisible(visible bool)
- func (w *Window) SetMatrix(m pixel.Matrix)
- func (w *Window) SetMonitor(monitor *Monitor)
- func (w *Window) SetSmooth(smooth bool)
- func (w *Window) SetTitle(title string)
- func (w *Window) SetVSync(vsync bool)
- func (w *Window) Smooth() bool
- func (w *Window) Typed() string
- func (w *Window) Update()
- func (w *Window) VSync() bool
- type WindowConfig
Constants ¶
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.
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.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(run func())
Run is essentially the main function of PixelGL. It exists mainly due to the technical limitations of OpenGL and operating systems. In short, all graphics and window manipulating calls must be done from the main thread. Run makes this possible.
Call this function from the main function of your application. This is necessary, so that Run runs on the main thread.
func run() { // interact with Pixel and PixelGL from here (even concurrently) } func main() { pixel.Run(run) }
You can spawn any number of goroutines from your run function and interact with PixelGL concurrently. The only condition is that the Run function is called from your main function.
Types ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
Canvas is an off-screen rectangular BasicTarget and Picture at the same time, that you can draw onto.
It supports TrianglesPosition, TrianglesColor, TrianglesPicture and PictureColor.
func (*Canvas) Color ¶
Color returns the color of the pixel over the given position inside the Canvas.
func (*Canvas) Draw ¶
Draw draws the content of the Canvas onto another Target, transformed by the given Matrix, just like if it was a Sprite containing the whole Canvas.
func (*Canvas) DrawColorMask ¶ added in v0.6.0
DrawColorMask draws the content of the Canvas onto another Target, transformed by the given Matrix and multiplied by the given mask, just like if it was a Sprite containing the whole Canvas.
If the color mask is nil, a fully opaque white mask will be used causing no effect.
func (*Canvas) MakePicture ¶
func (c *Canvas) MakePicture(p pixel.Picture) pixel.TargetPicture
MakePicture create a specialized copy of the supplied Picture that draws onto this Canvas.
PictureColor is supported.
func (*Canvas) MakeTriangles ¶
func (c *Canvas) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles
MakeTriangles creates a specialized copy of the supplied Triangles that draws onto this Canvas.
TrianglesPosition, TrianglesColor and TrianglesPicture are supported.
func (*Canvas) Pixels ¶ added in v0.5.1
Pixels returns an alpha-premultiplied RGBA sequence of the content of the Canvas.
func (*Canvas) SetBounds ¶
SetBounds resizes the Canvas to the new bounds. Old content will be preserved.
func (*Canvas) SetColorMask ¶
SetColorMask sets a color that every color in triangles or a picture will be multiplied by.
func (*Canvas) SetComposeMethod ¶
func (c *Canvas) SetComposeMethod(cmp pixel.ComposeMethod)
SetComposeMethod sets a Porter-Duff composition method to be used in the following draws onto this Canvas.
func (*Canvas) SetPixels ¶ added in v0.5.1
SetPixels replaces the content of the Canvas with the provided pixels. The provided slice must be an alpha-premultiplied RGBA sequence of correct length (4 * width * height).
func (*Canvas) SetSmooth ¶
SetSmooth sets whether stretched Pictures drawn onto this Canvas should be drawn smooth or pixely.
type GLFrame ¶
type GLFrame struct {
// contains filtered or unexported fields
}
GLFrame is a type that helps implementing OpenGL Targets. It implements most common methods to avoid code redundancy. It contains an glhf.Frame that you can draw on.
func NewGLFrame ¶
NewGLFrame creates a new GLFrame with the given bounds.
func (*GLFrame) Dirty ¶
func (gf *GLFrame) Dirty()
Dirty marks the GLFrame as changed. Always call this method when you draw onto the GLFrame's Frame.
type GLPicture ¶
type GLPicture interface { pixel.PictureColor Texture() *glhf.Texture }
GLPicture is a pixel.PictureColor with a Texture. All OpenGL Targets should implement and accept this interface, because it enables seamless drawing of one to another.
Implementing this interface on an OpenGL Target enables other OpenGL Targets to efficiently draw that Target onto them.
func NewGLPicture ¶
NewGLPicture creates a new GLPicture with it's own static OpenGL texture. This function always allocates a new texture that cannot (shouldn't) be further modified.
type GLTriangles ¶
type GLTriangles struct {
// contains filtered or unexported fields
}
GLTriangles are OpenGL triangles implemented using glhf.VertexSlice.
Triangles returned from this function support TrianglesPosition, TrianglesColor and TrianglesPicture. If you need to support more, you can "override" SetLen and Update methods.
func NewGLTriangles ¶
func NewGLTriangles(shader *glhf.Shader, t pixel.Triangles) *GLTriangles
NewGLTriangles returns GLTriangles initialized with the data from the supplied Triangles.
Only draw the Triangles using the provided Shader.
func (*GLTriangles) Color ¶
func (gt *GLTriangles) Color(i int) pixel.RGBA
Color returns the Color property of the i-th vertex.
func (*GLTriangles) Copy ¶
func (gt *GLTriangles) Copy() pixel.Triangles
Copy returns an independent copy of this GLTriangles.
The returned Triangles are *GLTriangles as the underlying type.
func (*GLTriangles) Picture ¶
func (gt *GLTriangles) Picture(i int) (pic pixel.Vec, intensity float64)
Picture returns the Picture property of the i-th vertex.
func (*GLTriangles) Position ¶
func (gt *GLTriangles) Position(i int) pixel.Vec
Position returns the Position property of the i-th vertex.
func (*GLTriangles) SetLen ¶
func (gt *GLTriangles) SetLen(len int)
SetLen efficiently resizes GLTriangles to len.
Time complexity is amortized O(1).
func (*GLTriangles) Shader ¶
func (gt *GLTriangles) Shader() *glhf.Shader
Shader returns the GLTriangles's associated shader.
func (*GLTriangles) Slice ¶
func (gt *GLTriangles) Slice(i, j int) pixel.Triangles
Slice returns a sub-Triangles of this GLTriangles in range [i, j).
func (*GLTriangles) Update ¶
func (gt *GLTriangles) Update(t pixel.Triangles)
Update copies vertex properties from the supplied Triangles into this GLTriangles.
The two Triangles (gt and t) must be of the same len.
func (*GLTriangles) VertexSlice ¶
func (gt *GLTriangles) VertexSlice() *glhf.VertexSlice
VertexSlice returns the VertexSlice of this GLTriangles.
You can use it to draw them.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor represents a physical display attached to your computer.
func Monitors ¶
func Monitors() []*Monitor
Monitors returns a slice of all currently available monitors.
func PrimaryMonitor ¶
func PrimaryMonitor() *Monitor
PrimaryMonitor returns the main monitor (usually the one with the taskbar and stuff).
func (*Monitor) PhysicalSize ¶
PhysicalSize returns the size of the display area of the Monitor in millimeters.
func (*Monitor) Position ¶
Position returns the position of the upper-left corner of the Monitor in screen coordinates.
func (*Monitor) RefreshRate ¶
RefreshRate returns the refresh frequency of the Monitor in Hz (refreshes/second).
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window is a window handler. Use this type to manipulate a window (input, drawing, etc.).
func NewWindow ¶
func NewWindow(cfg WindowConfig) (*Window, error)
NewWindow creates a new Window with it's properties specified in the provided config.
If Window creation fails, an error is returned (e.g. due to unavailable graphics device).
func (*Window) Closed ¶
Closed returns the closed flag of the Window, which reports whether the Window should be closed.
The closed flag is automatically set when a user attempts to close the Window.
func (*Window) Color ¶
Color returns the color of the pixel over the given position inside the Window.
func (*Window) CursorVisible ¶ added in v0.6.0
CursorVisible returns the visibility status of the mouse cursor.
func (*Window) Destroy ¶
func (w *Window) Destroy()
Destroy destroys the Window. The Window can't be used any further.
func (*Window) JustPressed ¶
JustPressed returns whether the Button has just been pressed down.
func (*Window) JustReleased ¶
JustReleased returns whether the Button has just been released up.
func (*Window) MakePicture ¶
func (w *Window) MakePicture(p pixel.Picture) pixel.TargetPicture
MakePicture generates a specialized copy of the supplied Picture that will draw onto this Window.
Window supports PictureColor.
func (*Window) MakeTriangles ¶
func (w *Window) MakeTriangles(t pixel.Triangles) pixel.TargetTriangles
MakeTriangles generates a specialized copy of the supplied Triangles that will draw onto this Window.
Window supports TrianglesPosition, TrianglesColor and TrianglesPicture.
func (*Window) Monitor ¶
Monitor returns a monitor the Window is fullscreen on. If the Window is not fullscreen, this function returns nil.
func (*Window) MousePosition ¶
MousePosition returns the current mouse position in the Window's Bounds.
func (*Window) MouseScroll ¶
MouseScroll returns the mouse scroll amount (in both axes) since the last call to Window.Update.
func (*Window) Repeated ¶ added in v0.6.0
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 (*Window) SetBounds ¶
SetBounds sets the bounds of the Window in pixels. Bounds can be fractional, but the actual size of the window will be rounded to integers.
func (*Window) SetClosed ¶
SetClosed sets the closed flag of the Window.
This is useful when overriding the user's attempt to close the Window, or just to close the Window from within the program.
func (*Window) SetColorMask ¶
SetColorMask sets a global color mask for the Window.
func (*Window) SetComposeMethod ¶
func (w *Window) SetComposeMethod(cmp pixel.ComposeMethod)
SetComposeMethod sets a Porter-Duff composition method to be used in the following draws onto this Window.
func (*Window) SetCursorVisible ¶ added in v0.6.0
SetCursorVisible sets the visibility of the mouse cursor inside the Window client area.
func (*Window) SetMonitor ¶
SetMonitor sets the Window fullscreen on the given Monitor. If the Monitor is nil, the Window will be restored to windowed state instead.
The Window will be automatically set to the Monitor's resolution. If you want a different resolution, you will need to set it manually with SetBounds method.
func (*Window) SetSmooth ¶
SetSmooth sets whether the stretched Pictures drawn onto this Window should be drawn smooth or pixely.
func (*Window) SetVSync ¶
SetVSync sets whether the Window's Update should synchronize with the monitor refresh rate.
func (*Window) Smooth ¶
Smooth returns whether the stretched Pictures drawn onto this Window are set to be drawn smooth or pixely.
func (*Window) Typed ¶ added in v0.6.0
Typed returns the text typed on the keyboard since the last call to Window.Update.
type WindowConfig ¶
type WindowConfig struct { // Title at the top of the Window. Title string // Icon specifies the icon images available to be used by the window. This is usually // displayed in the top bar of the window or in the task bar of the desktop environment. // // If passed one image, it will use that image, if passed an array of images those of or // closest to the sizes desired by the system are selected. The desired image sizes varies // depending on platform and system settings. The selected images will be rescaled as // needed. Good sizes include 16x16, 32x32 and 48x48. // // Note: Setting this value doesn't have an effect on OSX. You'll need to set the icon when // bundling your application for release. Icon []pixel.Picture // Bounds specify the bounds of the Window in pixels. Bounds pixel.Rect // If set to nil, the Window will be windowed. Otherwise it will be fullscreen on the // specified Monitor. Monitor *Monitor // Whether the Window is resizable. Resizable bool // Undecorated Window ommits the borders and decorations (close button, etc.). Undecorated bool // VSync (vertical synchronization) synchronizes Window's framerate with the framerate of // the monitor. VSync bool }
WindowConfig is a structure for specifying all possible properties of a Window. Properties are chosen in such a way, that you usually only need to set a few of them - defaults (zeros) should usually be sensible.
Note that you always need to set the Bounds of a Window.