Documentation
¶
Overview ¶
Package glfw experimentally provides a glfw-like API with desktop (via glfw) and browser (via HTML5 canvas) backends.
It is used for creating a GL context and receiving events.
Note: This package is currently in development. The API is incomplete and may change.
Index ¶
- Constants
- Variables
- func DefaultWindowHints()
- func DetachCurrentContext()
- func GetClipboardString() string
- func Init(cw ContextWatcher) error
- func Open(name string) (io.ReadCloser, error)
- func PollEvents() error
- func PostEmptyEvent()
- func SetClipboardString(str string)
- func SwapInterval(interval int) error
- func Terminate() error
- func WaitEvents()
- func WindowHint(target Hint, hint int)
- type Action
- type CharCallback
- type CharModsCallback
- type CloseCallback
- type ContextWatcher
- type CursorEnterCallback
- type CursorPosCallback
- type DropCallback
- type FocusCallback
- type FramebufferSizeCallback
- type GamepadAxis
- type GamepadButton
- type Hint
- type IconifyCallback
- type InputMode
- type Joystick
- type Key
- type KeyCallback
- type ModifierKey
- type Monitor
- type MouseButton
- type MouseButtonCallback
- type MouseMovementCallback
- type PosCallback
- type RefreshCallback
- type ScrollCallback
- type SizeCallback
- type VidMode
- type Window
- func (w *Window) Destroy()
- func (w *Window) GetClipboardString() string
- func (w *Window) GetCursorPos() (x, y float64)
- func (w *Window) GetFramebufferSize() (width, height int)
- func (w *Window) GetInputMode(mode InputMode) int
- func (w *Window) GetKey(key Key) Action
- func (w *Window) GetMouseButton(button MouseButton) Action
- func (w *Window) GetPos() (x, y int)
- func (w *Window) GetSize() (width, height int)
- func (w *Window) Hide()
- func (w *Window) MakeContextCurrent()
- func (w *Window) SetAttrib(attrib Hint, value int)
- func (w *Window) SetCharCallback(cbfun CharCallback) (previous CharCallback)
- func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsCallback)
- func (w *Window) SetClipboardString(str string)
- func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback)
- func (w *Window) SetCursorEnterCallback(cbfun CursorEnterCallback) (previous CursorEnterCallback)
- func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback)
- func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback)
- func (w *Window) SetFocusCallback(cbfun FocusCallback) (previous FocusCallback)
- func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback)
- func (w *Window) SetIcon(images interface{})
- func (w *Window) SetIconifyCallback(cbfun IconifyCallback) (previous IconifyCallback)
- func (w *Window) SetInputMode(mode InputMode, value int)
- func (w *Window) SetKeyCallback(cbfun KeyCallback) (previous KeyCallback)
- func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int)
- func (w *Window) SetMouseButtonCallback(cbfun MouseButtonCallback) (previous MouseButtonCallback)
- func (w *Window) SetMouseMovementCallback(cbfun MouseMovementCallback) (previous MouseMovementCallback)
- func (w *Window) SetPos(xpos, ypos int)
- func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback)
- func (w *Window) SetRefreshCallback(cbfun RefreshCallback) (previous RefreshCallback)
- func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallback)
- func (w *Window) SetShouldClose(value bool)
- func (w *Window) SetSize(width, height int)
- func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback)
- func (w *Window) SetTitle(title string)
- func (w *Window) ShouldClose() bool
- func (w *Window) Show()
- func (w *Window) SwapBuffers() error
Constants ¶
const ( True int = 1 False int = 0 DontCare int = -1 )
const ( MouseButton1 MouseButton = 0 MouseButton2 MouseButton = 2 // Web MouseEvent has middle and right mouse buttons in reverse order. MouseButton3 MouseButton = 1 // Web MouseEvent has middle and right mouse buttons in reverse order. MouseButtonLeft = MouseButton1 MouseButtonRight = MouseButton2 MouseButtonMiddle = MouseButton3 )
const ( CursorNormal = iota CursorHidden CursorDisabled )
Variables ¶
var ErrInvalidParameter = errors.New("invalid parameter")
var ErrInvalidValue = errors.New("invalid value")
Functions ¶
func DefaultWindowHints ¶
func DefaultWindowHints()
func DetachCurrentContext ¶
func DetachCurrentContext()
func GetClipboardString ¶ added in v0.2.0
func GetClipboardString() string
GetClipboardString returns the contents of the system clipboard, if it contains or is convertible to a UTF-8 encoded string.
This function may only be called from the main thread.
func Init ¶
func Init(cw ContextWatcher) error
func Open ¶
func Open(name string) (io.ReadCloser, error)
Open opens a named asset. It's the caller's responsibility to close it when done.
func PollEvents ¶
func PollEvents() error
func PostEmptyEvent ¶
func PostEmptyEvent()
func SetClipboardString ¶ added in v0.2.0
func SetClipboardString(str string)
SetClipboardString sets the system clipboard to the specified UTF-8 encoded string.
This function may only be called from the main thread.
func SwapInterval ¶
func WaitEvents ¶
func WaitEvents()
func WindowHint ¶
Types ¶
type CharCallback ¶
type CharModsCallback ¶
type CharModsCallback func(w *Window, char rune, mods ModifierKey)
type CloseCallback ¶
type CloseCallback func(w *Window)
type ContextWatcher ¶
type ContextWatcher interface {
// OnMakeCurrent is called after a context is made current.
// context is is a platform-specific representation of the context, or nil if unavailable.
OnMakeCurrent(context interface{})
// OnDetach is called after the current context is detached.
OnDetach()
}
ContextWatcher is a general mechanism for being notified when context is made current or detached.
type CursorEnterCallback ¶
type CursorPosCallback ¶
type DropCallback ¶
type FocusCallback ¶
type FramebufferSizeCallback ¶
type GamepadAxis ¶
type GamepadAxis int
const ( AxisLeftX GamepadAxis = iota AxisLeftY AxisRightX AxisRightY AxisLeftTrigger AxisRightTrigger AxisLast = AxisRightTrigger )
type GamepadButton ¶
type GamepadButton int
const ( ButtonA GamepadButton = iota ButtonB ButtonX ButtonY ButtonLeftBumper ButtonRightBumper ButtonBack ButtonStart ButtonGuide ButtonLeftThumb ButtonRightThumb ButtonDpadUp ButtonDpadRight ButtonDpadDown ButtonDpadLeft ButtonLast = ButtonDpadLeft ButtonCross = ButtonA ButtonCircle = ButtonB ButtonSquare = ButtonX ButtonTriangle = ButtonY )
type Hint ¶
type Hint int
const ( AlphaBits Hint = iota DepthBits StencilBits Samples Focused Iconified Maximized Visible Hovered Resizable Decorated Floating AutoIconify CenterCursor TransparentFramebuffer FocusOnShow ScaleToMonitor ClientAPI ContextVersionMajor ContextVersionMinor ContextRobustness ContextReleaseBehavior OpenGLForwardCompatible OpenGLDebugContext OpenGLProfile // goxjs/glfw-specific hints for WebGL. PremultipliedAlpha PreserveDrawingBuffer PreferLowPowerToHighPerformance FailIfMajorPerformanceCaveat )
type IconifyCallback ¶
type Joystick ¶
type Joystick int
const ( Joystick1 Joystick = iota Joystick2 Joystick3 Joystick4 Joystick5 Joystick6 Joystick7 Joystick8 Joystick9 Joystick10 Joystick11 Joystick12 Joystick13 Joystick14 Joystick15 Joystick16 JoystickLast = Joystick16 )
func (Joystick) GetButtons ¶
func (Joystick) GetGamepadName ¶
type Key ¶
type Key int
const ( KeyUnknown Key = -1 KeySpace Key = 32 KeyApostrophe Key = 222 KeyComma Key = 188 KeyMinus Key = 189 KeyPeriod Key = 190 KeySlash Key = 191 Key0 Key = 48 Key1 Key = 49 Key2 Key = 50 Key3 Key = 51 Key4 Key = 52 Key5 Key = 53 Key6 Key = 54 Key7 Key = 55 Key8 Key = 56 Key9 Key = 57 KeySemicolon Key = 186 KeyEqual Key = 187 KeyA Key = 65 KeyB Key = 66 KeyC Key = 67 KeyD Key = 68 KeyE Key = 69 KeyF Key = 70 KeyG Key = 71 KeyH Key = 72 KeyI Key = 73 KeyJ Key = 74 KeyK Key = 75 KeyL Key = 76 KeyM Key = 77 KeyN Key = 78 KeyO Key = 79 KeyP Key = 80 KeyQ Key = 81 KeyR Key = 82 KeyS Key = 83 KeyT Key = 84 KeyU Key = 85 KeyV Key = 86 KeyW Key = 87 KeyX Key = 88 KeyY Key = 89 KeyZ Key = 90 KeyLeftBracket Key = 219 KeyBackslash Key = 220 KeyRightBracket Key = 221 KeyGraveAccent Key = 192 KeyWorld1 Key = -iota - 2 KeyWorld2 Key = -iota - 2 KeyEscape Key = 27 KeyEnter Key = 13 KeyTab Key = 9 KeyBackspace Key = 8 KeyInsert Key = -iota - 2 KeyDelete Key = 46 KeyRight Key = 39 KeyLeft Key = 37 KeyDown Key = 40 KeyUp Key = 38 KeyPageUp Key = -iota - 2 KeyPageDown Key = -iota - 2 KeyHome Key = -iota - 2 KeyEnd Key = -iota - 2 KeyCapsLock Key = 20 KeyScrollLock Key = -iota - 2 KeyNumLock Key = -iota - 2 KeyPrintScreen Key = -iota - 2 KeyPause Key = -iota - 2 KeyF1 Key = 112 KeyF2 Key = 113 KeyF3 Key = 114 KeyF4 Key = 115 KeyF5 Key = 116 KeyF6 Key = 117 KeyF7 Key = 118 KeyF8 Key = 119 KeyF9 Key = 120 KeyF10 Key = 121 KeyF11 Key = 122 KeyF12 Key = 123 KeyF13 Key = -iota - 2 KeyF14 Key = -iota - 2 KeyF15 Key = -iota - 2 KeyF16 Key = -iota - 2 KeyF17 Key = -iota - 2 KeyF18 Key = -iota - 2 KeyF19 Key = -iota - 2 KeyF20 Key = -iota - 2 KeyF21 Key = -iota - 2 KeyF22 Key = -iota - 2 KeyF23 Key = -iota - 2 KeyF24 Key = -iota - 2 KeyF25 Key = -iota - 2 KeyKP0 Key = -iota - 2 KeyKP1 Key = -iota - 2 KeyKP2 Key = -iota - 2 KeyKP3 Key = -iota - 2 KeyKP4 Key = -iota - 2 KeyKP5 Key = -iota - 2 KeyKP6 Key = -iota - 2 KeyKP7 Key = -iota - 2 KeyKP8 Key = -iota - 2 KeyKP9 Key = -iota - 2 KeyKPDecimal Key = -iota - 2 KeyKPDivide Key = -iota - 2 KeyKPMultiply Key = -iota - 2 KeyKPSubtract Key = -iota - 2 KeyKPAdd Key = -iota - 2 KeyKPEnter Key = -iota - 2 KeyKPEqual Key = -iota - 2 KeyLeftShift Key = 340 KeyLeftControl Key = 341 KeyLeftAlt Key = 342 KeyLeftSuper Key = 91 KeyRightShift Key = 344 KeyRightControl Key = 345 KeyRightAlt Key = 346 KeyRightSuper Key = 93 KeyMenu Key = -iota - 2 )
TODO: Keys defined as -iota-2 need to be set to a valid positive value that matches the keyCode
generated by browsers. -iota-2 is used as a temporary solution to have unique but invalid values. See https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode.
type KeyCallback ¶
type KeyCallback func(w *Window, key Key, scancode int, action Action, mods ModifierKey)
type ModifierKey ¶
type ModifierKey int
const ( ModShift ModifierKey = (1 << iota) ModControl ModAlt ModSuper )
type Monitor ¶
type Monitor struct{}
func GetPrimaryMonitor ¶
func GetPrimaryMonitor() *Monitor
func (*Monitor) GetVideoMode ¶
type MouseButton ¶
type MouseButton int
type MouseButtonCallback ¶
type MouseButtonCallback func(w *Window, button MouseButton, action Action, mods ModifierKey)
type MouseMovementCallback ¶
type PosCallback ¶
type RefreshCallback ¶
type RefreshCallback func(w *Window)
type ScrollCallback ¶
type SizeCallback ¶
type VidMode ¶
type VidMode struct {
Width int // The width, in pixels, of the video mode.
Height int // The height, in pixels, of the video mode.
RedBits int // The bit depth of the red channel of the video mode.
GreenBits int // The bit depth of the green channel of the video mode.
BlueBits int // The bit depth of the blue channel of the video mode.
RefreshRate int // The refresh rate, in Hz, of the video mode.
}
VidMode describes a single video mode.
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
func CreateWindow ¶
func GetCurrentContext ¶
func GetCurrentContext() *Window
func (*Window) GetClipboardString ¶
func (*Window) GetCursorPos ¶
func (*Window) GetFramebufferSize ¶
func (*Window) GetInputMode ¶
func (*Window) GetMouseButton ¶
func (w *Window) GetMouseButton(button MouseButton) Action
func (*Window) MakeContextCurrent ¶
func (w *Window) MakeContextCurrent()
func (*Window) SetCharCallback ¶
func (w *Window) SetCharCallback(cbfun CharCallback) (previous CharCallback)
func (*Window) SetCharModsCallback ¶
func (w *Window) SetCharModsCallback(cbfun CharModsCallback) (previous CharModsCallback)
func (*Window) SetClipboardString ¶
func (*Window) SetCloseCallback ¶
func (w *Window) SetCloseCallback(cbfun CloseCallback) (previous CloseCallback)
func (*Window) SetCursorEnterCallback ¶
func (w *Window) SetCursorEnterCallback(cbfun CursorEnterCallback) (previous CursorEnterCallback)
func (*Window) SetCursorPosCallback ¶
func (w *Window) SetCursorPosCallback(cbfun CursorPosCallback) (previous CursorPosCallback)
func (*Window) SetDropCallback ¶
func (w *Window) SetDropCallback(cbfun DropCallback) (previous DropCallback)
func (*Window) SetFocusCallback ¶
func (w *Window) SetFocusCallback(cbfun FocusCallback) (previous FocusCallback)
func (*Window) SetFramebufferSizeCallback ¶
func (w *Window) SetFramebufferSizeCallback(cbfun FramebufferSizeCallback) (previous FramebufferSizeCallback)
func (*Window) SetIconifyCallback ¶
func (w *Window) SetIconifyCallback(cbfun IconifyCallback) (previous IconifyCallback)
func (*Window) SetInputMode ¶
func (*Window) SetKeyCallback ¶
func (w *Window) SetKeyCallback(cbfun KeyCallback) (previous KeyCallback)
func (*Window) SetMonitor ¶
func (*Window) SetMouseButtonCallback ¶
func (w *Window) SetMouseButtonCallback(cbfun MouseButtonCallback) (previous MouseButtonCallback)
func (*Window) SetMouseMovementCallback ¶
func (w *Window) SetMouseMovementCallback(cbfun MouseMovementCallback) (previous MouseMovementCallback)
func (*Window) SetPosCallback ¶
func (w *Window) SetPosCallback(cbfun PosCallback) (previous PosCallback)
func (*Window) SetRefreshCallback ¶
func (w *Window) SetRefreshCallback(cbfun RefreshCallback) (previous RefreshCallback)
func (*Window) SetScrollCallback ¶
func (w *Window) SetScrollCallback(cbfun ScrollCallback) (previous ScrollCallback)
func (*Window) SetShouldClose ¶
func (*Window) SetSizeCallback ¶
func (w *Window) SetSizeCallback(cbfun SizeCallback) (previous SizeCallback)