glfw

package module
v0.0.0-...-6c10ac2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 7 Imported by: 0

README

glfw

This package provides a very thin purego Go binding for the GLFW 3.4 library. GLFW provides a simple API for creating windows, contexts and surfaces, receiving input, and events, with support for Windows, macOS, Wayland and X11.

Install

go get github.com/jdpalmer/glfw

Note: This package provides the bindings only. You must also have the native GLFW dynamic library installed on your system or bundled with your application.

Platform-Specific Setup

Windows

Download the pre-compiled binaries from [https://glfw.org/]. For distribution, include the glfw3.dll in the same directory as your application binary.

Linux (Ubuntu/Debian)

Install via the package manager:

sudo apt install libglfw3

You should also ensure your system has the necessary development headers for OpenGL, OpenGL ES, or Vulkan depending on your target graphics API. You can also install these with apt.

MacOS

While Homebrew provides a glfw package, it is often unsuitable for production applications due to a lack of rpath support and inability to easily link with ANGLE (for OpenGL ES).

Recommended: Use the official binary distribution from glfw.org. For bundled macOS applications (.app), use the following structure:

YourApp.app/
  Contents/
    MacOS/YourApp
    Frameworks/
      libglfw.3.dylib
      libEGL.dylib
      libGLESv2.dylib

Configuring rpath

To ensure your binary finds the dynamic libraries at runtime, add the rpath to your executable:

go build -o YourApp.app/Contents/MacOS/YourApp ./cmd/yourapp
install_name_tool -add_rpath '@executable_path/../Frameworks' \
  YourApp.app/Contents/MacOS/YourApp

If you are using CGO/external linking, you can bake this into the build process:

CGO_ENABLED=1 go build \
  -ldflags '-extldflags=-Wl,-rpath,@executable_path/../Frameworks' \
  -o YourApp.app/Contents/MacOS/YourApp ./cmd/yourapp

For rapid development, you may simply place the .dylib files in the same folder as your binary.

Quick Start Example

package main

import (
	"fmt"

	"github.com/jdpalmer/glfw"
)

func main() {
	if err := glfw.Init(); err != nil {
		fmt.Println(err)
		return
	}
	defer glfw.Terminate()

	window := glfw.CreateWindow(640, 480, "GLFW Test", nil, nil)
	if window == nil {
		fmt.Println("Failed to create window")
		return
	}
	defer window.Destroy()

	window.MakeContextCurrent()
	for !window.ShouldClose() {
		window.SwapBuffers()
		glfw.PollEvents()
	}
}

Threading Requirements

GLFW has strict threading requirements. Most calls must be executed on the main thread.

  • glfw.Init automatically calls runtime.LockOSThread on the caller.
  • Ensure that all window creation, context management, and event polling occur on this locked main thread.

Documentation

  • API Reference: Use the official GLFW Documentation.
  • Go Bindings: Use go doc github.com/jdpalmer/glfw for package-specific details.

License

MIT — see LICENSE. GLFW itself is licensed separately (zlib).

Documentation

Overview

glfw is a purego binding of GLFW 3.4.

Threading

Most GLFW calls must run on the main thread. Init locks the calling OS thread via runtime.LockOSThread; keep event polling and window creation on that thread.

Handles and GC

Window, Monitor, and Cursor are Go-owned wrappers around opaque C handles. Callbacks receive the same Go *Window / *Monitor values registered at create time. User data from SetUserPointer is stored on the Go wrapper as any; it is not written into GLFW's C user-pointer slot, so the GC can track it safely.

Callbacks use one stable C trampoline per callback kind. Set*Callback replaces the Go func and returns the previous one. Destroy and Terminate clear retained callbacks and handle maps.

Shared libraries and EGL (macOS)

Init loads libglfw from system paths, Homebrew locations, the executable directory, or Contents/Frameworks. For EGL/OpenGL ES contexts, GLFW itself loads libEGL and libGLESv2 by leaf name. On macOS that requires packaging those dylibs where dyld can see them (typically Contents/Frameworks with an LC_RPATH of @executable_path/../Frameworks on the main binary). A Homebrew libglfw alone is not a viable way to ship EGL/ANGLE; see the README.

Index

Constants

View Source
const (
	VersionMajor    = 3
	VersionMinor    = 4
	VersionRevision = 0
)

Version constants.

View Source
const (
	CursorNormal   int32 = 0x00034001
	CursorHidden   int32 = 0x00034002
	CursorDisabled int32 = 0x00034003
	CursorCaptured int32 = 0x00034004
)

Cursor mode values (use with InputMode CursorMode).

View Source
const (
	True  int32 = 1
	False int32 = 0

	NoAPI       int32 = 0
	OpenGLAPI   int32 = 0x00030001
	OpenGLESAPI int32 = 0x00030002

	NoRobustness        int32 = 0
	NoResetNotification int32 = 0x00031001
	LoseContextOnReset  int32 = 0x00031002

	OpenGLAnyProfile    int32 = 0
	OpenGLCoreProfile   int32 = 0x00032001
	OpenGLCompatProfile int32 = 0x00032002

	AnyReleaseBehavior   int32 = 0
	ReleaseBehaviorFlush int32 = 0x00035001
	ReleaseBehaviorNone  int32 = 0x00035002

	NativeContextAPI int32 = 0x00036001
	EGLContextAPI    int32 = 0x00036002
	OSMesaContextAPI int32 = 0x00036003

	AnglePlatformTypeNone     int32 = 0x00037001
	AnglePlatformTypeOpenGL   int32 = 0x00037002
	AnglePlatformTypeOpenGLES int32 = 0x00037003
	AnglePlatformTypeD3D9     int32 = 0x00037004
	AnglePlatformTypeD3D11    int32 = 0x00037005
	AnglePlatformTypeVulkan   int32 = 0x00037007
	AnglePlatformTypeMetal    int32 = 0x00037008

	WaylandPreferLibdecor  int32 = 0x00038001
	WaylandDisableLibdecor int32 = 0x00038002

	AnyPosition int32 = -0x80000000
	DontCare    int32 = -1
)

Variables

This section is empty.

Functions

func DefaultWindowHints

func DefaultWindowHints()

DefaultWindowHints resets all window hints to their default values.

func ExtensionSupported

func ExtensionSupported(extension string) bool

ExtensionSupported reports whether the specified OpenGL or OpenGL ES extension is supported.

func GamepadName

func GamepadName(jid Joystick) string

GamepadName returns the human-readable name of the gamepad mapped to the joystick.

func GetJoystickAxes

func GetJoystickAxes(jid Joystick) ([]float32, error)

GetJoystickAxes returns the values of all axes of the specified joystick.

func GetJoystickButtons

func GetJoystickButtons(jid Joystick) ([]byte, error)

GetJoystickButtons returns the state of all buttons of the specified joystick.

func GetJoystickHats

func GetJoystickHats(jid Joystick) ([]byte, error)

GetJoystickHats returns the state of all hats of the specified joystick.

func GetKeyName

func GetKeyName(key Key, scancode int32) string

GetKeyName returns the printable name of a key.

func GetKeyScancode

func GetKeyScancode(key Key) int32

GetKeyScancode returns the platform-specific scancode of a key.

func GetProcAddress

func GetProcAddress(procname string) unsafe.Pointer

GetProcAddress returns a raw OpenGL/OpenGL ES function pointer (not a Go func value). Pass it directly to your GL loader.

func GetRequiredInstanceExtensions

func GetRequiredInstanceExtensions() []string

GetRequiredInstanceExtensions returns the Vulkan instance extensions required by GLFW.

func GetTime

func GetTime() float64

GetTime returns the value of the GLFW timer in seconds.

func GetTimerFrequency

func GetTimerFrequency() uint64

GetTimerFrequency returns the frequency of the raw timer in Hz.

func GetTimerValue

func GetTimerValue() uint64

GetTimerValue returns the current value of the raw timer.

func GetVersion

func GetVersion() (major, minor, rev int32)

GetVersion returns the compile-time major, minor, and revision of the GLFW library.

func GetVersionString

func GetVersionString() string

GetVersionString returns a compile-time version string for the GLFW library.

func Init

func Init() error

Init loads the platform GLFW shared library, registers trampolines, locks the OS thread, and initializes GLFW. Call Terminate before exit.

func JoystickGUID

func JoystickGUID(jid Joystick) string

JoystickGUID returns the SDL-compatible GUID of the specified joystick.

func JoystickIsGamepad

func JoystickIsGamepad(jid Joystick) bool

JoystickIsGamepad reports whether the joystick has a gamepad mapping.

func JoystickName

func JoystickName(jid Joystick) string

JoystickName returns the name of the specified joystick.

func JoystickPresent

func JoystickPresent(jid Joystick) bool

JoystickPresent reports whether the specified joystick is present.

func JoystickUserPointer

func JoystickUserPointer(jid Joystick) any

JoystickUserPointer returns the value previously passed to SetJoystickUserPointer.

func PlatformSupported

func PlatformSupported(platform PlatformID) bool

PlatformSupported reports whether the specified platform is supported on this machine.

func PollEvents

func PollEvents()

PollEvents processes pending events without blocking.

func PostEmptyEvent

func PostEmptyEvent()

PostEmptyEvent posts an empty event from another thread to wake WaitEvents.

func RawMouseMotionSupported

func RawMouseMotionSupported() bool

RawMouseMotionSupported reports whether raw mouse motion is supported.

func SetJoystickUserPointer

func SetJoystickUserPointer(jid Joystick, ptr any)

SetJoystickUserPointer stores an arbitrary Go value for a joystick.

func SetTime

func SetTime(time float64)

SetTime sets the value of the GLFW timer in seconds.

func SwapInterval

func SwapInterval(interval int32)

SwapInterval sets the swap interval for the current OpenGL or OpenGL ES context.

func Terminate

func Terminate()

Terminate shuts down GLFW and clears handle maps, user data, and global callbacks.

func UpdateGamepadMappings

func UpdateGamepadMappings(str string) bool

UpdateGamepadMappings adds or updates gamepad mappings from an ASCII string.

func VulkanSupported

func VulkanSupported() bool

VulkanSupported reports whether the Vulkan loader and an ICD have been found.

func WaitEvents

func WaitEvents()

WaitEvents waits until events are available and processes them.

func WaitEventsTimeout

func WaitEventsTimeout(timeout float64)

WaitEventsTimeout waits with timeout for events and then processes them.

func WindowHint

func WindowHint(hint Hint, value int32)

WindowHint sets a window creation hint. hint is a Hint name; value is typically True/False, an API enumerant (OpenGLAPI, OpenGLCoreProfile, …), DontCare, or a size.

When hint is ContextCreationAPI/EGLContextAPI or ClientAPI/OpenGLESAPI, this also tries to Dlopen EGL or GLESv2 from the same search paths as Init (system, Homebrew, Frameworks, sibling). On Windows that often helps GLFW's later LoadLibrary by basename. On macOS, GLFW still loads those libs by leaf name using dyld search rules; preload alone is not enough — see the README packaging notes.

func WindowHintString

func WindowHintString(hint Hint, value string)

WindowHintString sets a string-valued window hint.

Types

type Action

type Action int32

Action corresponds to a key or button action.

const (
	Release Action = 0
	Press   Action = 1
	Repeat  Action = 2
)

type CharFunc

type CharFunc func(window *Window, codepoint uint32)

type CharModsFunc

type CharModsFunc func(window *Window, codepoint uint32, mods ModifierKey)

type Cursor

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

Cursor is a Go-owned wrapper around a GLFWcursor*.

func CreateCursor

func CreateCursor(image *Image, xhot, yhot int32) *Cursor

CreateCursor creates a cursor from an RGBA image. image pixels must remain reachable until the call returns (GLFW copies them).

func CreateStandardCursor

func CreateStandardCursor(shape StandardCursor) *Cursor

CreateStandardCursor creates a cursor from a standard shape.

func (*Cursor) Destroy

func (c *Cursor) Destroy()

Destroy destroys the cursor and unregisters it from the handle map.

type CursorEnterFunc

type CursorEnterFunc func(window *Window, entered int32)

type CursorPosFunc

type CursorPosFunc func(window *Window, xpos float64, ypos float64)

type DropFunc

type DropFunc func(window *Window, paths []string)

type ErrorCode

type ErrorCode int32

ErrorCode corresponds to an error code.

const (
	NoError              ErrorCode = 0
	NotInitialized       ErrorCode = 0x00010001
	NoCurrentContext     ErrorCode = 0x00010002
	InvalidEnum          ErrorCode = 0x00010003
	InvalidValue         ErrorCode = 0x00010004
	OutOfMemory          ErrorCode = 0x00010005
	APIUnavailable       ErrorCode = 0x00010006
	VersionUnavailable   ErrorCode = 0x00010007
	PlatformError        ErrorCode = 0x00010008
	FormatUnavailable    ErrorCode = 0x00010009
	NoWindowContext      ErrorCode = 0x0001000A
	CursorUnavailable    ErrorCode = 0x0001000B
	FeatureUnavailable   ErrorCode = 0x0001000C
	FeatureUnimplemented ErrorCode = 0x0001000D
	PlatformUnavailable  ErrorCode = 0x0001000E
)

func GetError

func GetError() (code ErrorCode, description string)

GetError returns and clears the last error code and its UTF-8 description.

type ErrorFunc

type ErrorFunc func(errorCode ErrorCode, description string)

func SetErrorCallback

func SetErrorCallback(cb ErrorFunc) ErrorFunc

SetErrorCallback sets the global error callback and returns the previous one. Pass nil to remove. The callback may be invoked on any thread GLFW uses.

type FramebufferSizeFunc

type FramebufferSizeFunc func(window *Window, width int32, height int32)

type GamepadAxis

type GamepadAxis int32

GamepadAxis corresponds to a gamepad axis.

const (
	GamepadAxisLeftX        GamepadAxis = 0
	GamepadAxisLeftY        GamepadAxis = 1
	GamepadAxisRightX       GamepadAxis = 2
	GamepadAxisRightY       GamepadAxis = 3
	GamepadAxisLeftTrigger  GamepadAxis = 4
	GamepadAxisRightTrigger GamepadAxis = 5
	GamepadAxisLast         GamepadAxis = GamepadAxisRightTrigger
)

type GamepadButton

type GamepadButton int32

GamepadButton corresponds to a gamepad button.

const (
	GamepadButtonA           GamepadButton = 0
	GamepadButtonB           GamepadButton = 1
	GamepadButtonX           GamepadButton = 2
	GamepadButtonY           GamepadButton = 3
	GamepadButtonLeftBumper  GamepadButton = 4
	GamepadButtonRightBumper GamepadButton = 5
	GamepadButtonBack        GamepadButton = 6
	GamepadButtonStart       GamepadButton = 7
	GamepadButtonGuide       GamepadButton = 8
	GamepadButtonLeftThumb   GamepadButton = 9
	GamepadButtonRightThumb  GamepadButton = 10
	GamepadButtonDpadUp      GamepadButton = 11
	GamepadButtonDpadRight   GamepadButton = 12
	GamepadButtonDpadDown    GamepadButton = 13
	GamepadButtonDpadLeft    GamepadButton = 14
	GamepadButtonLast        GamepadButton = GamepadButtonDpadLeft
	GamepadButtonCross       GamepadButton = GamepadButtonA
	GamepadButtonCircle      GamepadButton = GamepadButtonB
	GamepadButtonSquare      GamepadButton = GamepadButtonX
	GamepadButtonTriangle    GamepadButton = GamepadButtonY
)

type GamepadState

type GamepadState struct {
	Buttons [15]byte
	Axes    [6]float32
}

func GetGamepadState

func GetGamepadState(jid Joystick) (*GamepadState, int32)

GetGamepadState returns the gamepad input state for the specified joystick.

type GammaRamp

type GammaRamp struct {
	Red   []uint16
	Green []uint16
	Blue  []uint16
	Size  uint32
}

type Hint

type Hint int32
const (
	Focused                Hint = 0x00020001
	Iconified              Hint = 0x00020002
	Resizable              Hint = 0x00020003
	Visible                Hint = 0x00020004
	Decorated              Hint = 0x00020005
	AutoIconify            Hint = 0x00020006
	Floating               Hint = 0x00020007
	Maximized              Hint = 0x00020008
	CenterCursor           Hint = 0x00020009
	TransparentFramebuffer Hint = 0x0002000A
	Hovered                Hint = 0x0002000B
	FocusOnShow            Hint = 0x0002000C
	MousePassthrough       Hint = 0x0002000D
	PositionX              Hint = 0x0002000E
	PositionY              Hint = 0x0002000F

	RedBits        Hint = 0x00021001
	GreenBits      Hint = 0x00021002
	BlueBits       Hint = 0x00021003
	AlphaBits      Hint = 0x00021004
	DepthBits      Hint = 0x00021005
	StencilBits    Hint = 0x00021006
	AccumRedBits   Hint = 0x00021007
	AccumGreenBits Hint = 0x00021008
	AccumBlueBits  Hint = 0x00021009
	AccumAlphaBits Hint = 0x0002100A
	AuxBuffers     Hint = 0x0002100B
	Stereo         Hint = 0x0002100C
	Samples        Hint = 0x0002100D
	SRGBCapable    Hint = 0x0002100E
	RefreshRate    Hint = 0x0002100F
	Doublebuffer   Hint = 0x00021010

	ClientAPI              Hint = 0x00022001
	ContextVersionMajor    Hint = 0x00022002
	ContextVersionMinor    Hint = 0x00022003
	ContextRevision        Hint = 0x00022004
	ContextRobustness      Hint = 0x00022005
	OpenGLForwardCompat    Hint = 0x00022006
	ContextDebug           Hint = 0x00022007
	OpenGLDebugContext     Hint = ContextDebug
	OpenGLProfile          Hint = 0x00022008
	ContextReleaseBehavior Hint = 0x00022009
	ContextNoError         Hint = 0x0002200A
	ContextCreationAPI     Hint = 0x0002200B
	ScaleToMonitor         Hint = 0x0002200C
	ScaleFramebuffer       Hint = 0x0002200D
	CocoaRetinaFramebuffer Hint = 0x00023001
	CocoaFrameName         Hint = 0x00023002
	CocoaGraphicsSwitching Hint = 0x00023003
	X11ClassName           Hint = 0x00024001
	X11InstanceName        Hint = 0x00024002
	Win32KeyboardMenu      Hint = 0x00025001
	Win32ShowDefault       Hint = 0x00025002
	WaylandAppID           Hint = 0x00026001

	JoystickHatButtons  Hint = 0x00050001
	AnglePlatformType   Hint = 0x00050002
	Platform            Hint = 0x00050003
	CocoaChdirResources Hint = 0x00051001
	CocoaMenubar        Hint = 0x00051002
	X11XcbVulkanSurface Hint = 0x00052001
	WaylandLibdecor     Hint = 0x00053001
)

type Image

type Image struct {
	Width  int32
	Height int32
	Pixels []byte
}

type InputMode

type InputMode int32

InputMode corresponds to an input mode.

const (
	CursorMode         InputMode = 0x00033001
	StickyKeys         InputMode = 0x00033002
	StickyMouseButtons InputMode = 0x00033003
	LockKeyMods        InputMode = 0x00033004
	RawMouseMotion     InputMode = 0x00033005
)

type Joystick

type Joystick int32

Joystick corresponds to a joystick ID.

const (
	Joystick1    Joystick = 0
	Joystick2    Joystick = 1
	Joystick3    Joystick = 2
	Joystick4    Joystick = 3
	Joystick5    Joystick = 4
	Joystick6    Joystick = 5
	Joystick7    Joystick = 6
	Joystick8    Joystick = 7
	Joystick9    Joystick = 8
	Joystick10   Joystick = 9
	Joystick11   Joystick = 10
	Joystick12   Joystick = 11
	Joystick13   Joystick = 12
	Joystick14   Joystick = 13
	Joystick15   Joystick = 14
	Joystick16   Joystick = 15
	JoystickLast Joystick = Joystick16
)

type JoystickFunc

type JoystickFunc func(jid Joystick, event PeripheralEvent)

func SetJoystickCallback

func SetJoystickCallback(cb JoystickFunc) JoystickFunc

SetJoystickCallback sets the global joystick connection callback and returns the previous one.

type JoystickHatState

type JoystickHatState int32

JoystickHatState corresponds to joystick hat states.

const (
	HatCentered  JoystickHatState = 0
	HatUp        JoystickHatState = 1
	HatRight     JoystickHatState = 2
	HatDown      JoystickHatState = 4
	HatLeft      JoystickHatState = 8
	HatRightUp   JoystickHatState = HatRight | HatUp
	HatRightDown JoystickHatState = HatRight | HatDown
	HatLeftUp    JoystickHatState = HatLeft | HatUp
	HatLeftDown  JoystickHatState = HatLeft | HatDown
)

type Key

type Key int32

Key corresponds to a keyboard key.

const (
	KeyUnknown Key = -1

	// Printable keys
	KeySpace        Key = 32
	KeyApostrophe   Key = 39 // '
	KeyComma        Key = 44 // ,
	KeyMinus        Key = 45 // -
	KeyPeriod       Key = 46 // .
	KeySlash        Key = 47 // /
	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 = 59 // ;
	KeyEqual        Key = 61 // =
	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 = 91  // [
	KeyBackslash    Key = 92  // \
	KeyRightBracket Key = 93  // ]
	KeyGraveAccent  Key = 96  // `
	KeyWorld_1      Key = 161 // non-US #1
	KeyWorld_2      Key = 162 // non-US #2

	// Function keys
	KeyEscape        Key = 256
	KeyEnter         Key = 257
	KeyTab           Key = 258
	KeyBackspace     Key = 259
	KeyInsert        Key = 260
	KeyDelete        Key = 261
	KeyRight         Key = 262
	KeyLeft          Key = 263
	KeyDown          Key = 264
	KeyUp            Key = 265
	KeyPageUp        Key = 266
	KeyPageDown      Key = 267
	KeyHome          Key = 268
	KeyEnd           Key = 269
	KeyCapsLock      Key = 280
	KeyScrollLock    Key = 281
	KeyNumLock       Key = 282
	KeyPrintScreen   Key = 283
	KeyPause         Key = 284
	KeyF1            Key = 290
	KeyF2            Key = 291
	KeyF3            Key = 292
	KeyF4            Key = 293
	KeyF5            Key = 294
	KeyF6            Key = 295
	KeyF7            Key = 296
	KeyF8            Key = 297
	KeyF9            Key = 298
	KeyF10           Key = 299
	KeyF11           Key = 300
	KeyF12           Key = 301
	KeyF13           Key = 302
	KeyF14           Key = 303
	KeyF15           Key = 304
	KeyF16           Key = 305
	KeyF17           Key = 306
	KeyF18           Key = 307
	KeyF19           Key = 308
	KeyF20           Key = 309
	KeyF21           Key = 310
	KeyF22           Key = 311
	KeyF23           Key = 312
	KeyF24           Key = 313
	KeyF25           Key = 314
	KeyKP_0          Key = 320
	KeyKP_1          Key = 321
	KeyKP_2          Key = 322
	KeyKP_3          Key = 323
	KeyKP_4          Key = 324
	KeyKP_5          Key = 325
	KeyKP_6          Key = 326
	KeyKP_7          Key = 327
	KeyKP_8          Key = 328
	KeyKP_9          Key = 329
	KeyKP_Decimal    Key = 330
	KeyKP_Divide     Key = 331
	KeyKP_Multiply   Key = 332
	KeyKP_Subtract   Key = 333
	KeyKP_Add        Key = 334
	KeyKP_Enter      Key = 335
	KeyKP_Equal      Key = 336
	KeyLeft_Shift    Key = 340
	KeyLeft_Control  Key = 341
	KeyLeft_Alt      Key = 342
	KeyLeft_Super    Key = 343
	KeyRight_Shift   Key = 344
	KeyRight_Control Key = 345
	KeyRight_Alt     Key = 346
	KeyRight_Super   Key = 347
	KeyMenu          Key = 348
	KeyLast          Key = KeyMenu
)

type KeyFunc

type KeyFunc func(window *Window, key Key, scancode int32, action Action, mods ModifierKey)

type ModifierKey

type ModifierKey int32

ModifierKey corresponds to a modifier key.

const (
	ModShift    ModifierKey = 0x0001
	ModControl  ModifierKey = 0x0002
	ModAlt      ModifierKey = 0x0004
	ModSuper    ModifierKey = 0x0008
	ModCapsLock ModifierKey = 0x0010
	ModNumLock  ModifierKey = 0x0020
)

type Monitor

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

Monitor is a Go-owned wrapper around a GLFWmonitor*. Use SetUserPointer to attach Go values; they are not stored in C.

func GetMonitors

func GetMonitors() ([]*Monitor, error)

GetMonitors returns the currently connected monitors.

func GetPrimaryMonitor

func GetPrimaryMonitor() *Monitor

GetPrimaryMonitor returns the primary monitor.

func (*Monitor) ContentScale

func (m *Monitor) ContentScale() (xscale, yscale float32)

ContentScale returns the content scale of the monitor.

func (*Monitor) GammaRamp

func (m *Monitor) GammaRamp() GammaRamp

GammaRamp returns the current gamma ramp of the monitor.

func (*Monitor) Name

func (m *Monitor) Name() string

Name returns a human-readable name of the monitor.

func (*Monitor) PhysicalSize

func (m *Monitor) PhysicalSize() (wMM, hMM int32)

PhysicalSize returns the physical size of the monitor in millimetres.

func (*Monitor) Pos

func (m *Monitor) Pos() (x, y int32)

Pos returns the position of the monitor's viewport on the virtual desktop.

func (*Monitor) SetGamma

func (m *Monitor) SetGamma(gamma float32)

SetGamma generates a gamma ramp from the specified exponent and applies it.

func (*Monitor) SetGammaRamp

func (m *Monitor) SetGammaRamp(ramp *GammaRamp)

SetGammaRamp sets the current gamma ramp of the monitor.

func (*Monitor) SetUserPointer

func (m *Monitor) SetUserPointer(ptr any)

SetUserPointer stores an arbitrary Go value on this monitor (Go-side only).

func (*Monitor) UserPointer

func (m *Monitor) UserPointer() any

UserPointer returns the value previously passed to SetUserPointer.

func (*Monitor) VideoMode

func (m *Monitor) VideoMode() VidMode

VideoMode returns the current video mode of the monitor.

func (*Monitor) VideoModes

func (m *Monitor) VideoModes() []VidMode

VideoModes returns all video modes supported by the monitor.

func (*Monitor) Workarea

func (m *Monitor) Workarea() (x, y, w2, h int32)

Workarea returns the work area of the monitor.

type MonitorFunc

type MonitorFunc func(monitor *Monitor, event PeripheralEvent)

func SetMonitorCallback

func SetMonitorCallback(cb MonitorFunc) MonitorFunc

SetMonitorCallback sets the global monitor connection callback and returns the previous one.

type MouseButton

type MouseButton int32

MouseButton corresponds to a mouse button.

const (
	MouseButton1      MouseButton = 0
	MouseButton2      MouseButton = 1
	MouseButton3      MouseButton = 2
	MouseButton4      MouseButton = 3
	MouseButton5      MouseButton = 4
	MouseButton6      MouseButton = 5
	MouseButton7      MouseButton = 6
	MouseButton8      MouseButton = 7
	MouseButtonLast   MouseButton = MouseButton8
	MouseButtonLeft   MouseButton = MouseButton1
	MouseButtonRight  MouseButton = MouseButton2
	MouseButtonMiddle MouseButton = MouseButton3
)

type MouseButtonFunc

type MouseButtonFunc func(window *Window, button MouseButton, action Action, mods ModifierKey)

type PeripheralEvent

type PeripheralEvent int32

PeripheralEvent corresponds to a monitor or joystick connection event.

const (
	Connected    PeripheralEvent = 0x00040001
	Disconnected PeripheralEvent = 0x00040002
)

type PlatformID

type PlatformID int32

PlatformID corresponds to a platform returned by GetPlatform.

const (
	AnyPlatform     PlatformID = 0x00060000
	PlatformWin32   PlatformID = 0x00060001
	PlatformCocoa   PlatformID = 0x00060002
	PlatformWayland PlatformID = 0x00060003
	PlatformX11     PlatformID = 0x00060004
	PlatformNull    PlatformID = 0x00060005
)

func GetPlatform

func GetPlatform() PlatformID

GetPlatform returns the currently selected platform.

type ScrollFunc

type ScrollFunc func(window *Window, xoffset float64, yoffset float64)

type StandardCursor

type StandardCursor int32

StandardCursor corresponds to a standard cursor shape.

const (
	ArrowCursor        StandardCursor = 0x00036001
	IbeamCursor        StandardCursor = 0x00036002
	CrosshairCursor    StandardCursor = 0x00036003
	PointingHandCursor StandardCursor = 0x00036004
	ResizeEWCursor     StandardCursor = 0x00036005
	ResizeNSCursor     StandardCursor = 0x00036006
	ResizeNWSECursor   StandardCursor = 0x00036007
	ResizeNESWCursor   StandardCursor = 0x00036008
	ResizeAllCursor    StandardCursor = 0x00036009
	NotAllowedCursor   StandardCursor = 0x0003600A
	HResizeCursor      StandardCursor = ResizeEWCursor
	VResizeCursor      StandardCursor = ResizeNSCursor
	HandCursor         StandardCursor = PointingHandCursor
)

type VidMode

type VidMode struct {
	Width       int32
	Height      int32
	RedBits     int32
	GreenBits   int32
	BlueBits    int32
	RefreshRate int32
}

type Window

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

Window is a Go-owned wrapper around a GLFWwindow*. Callbacks installed with Set*Callback receive this same *Window. Use SetUserPointer to attach Go values; they are not stored in C.

func CreateWindow

func CreateWindow(width, height int32, title string, monitor *Monitor, share *Window) *Window

CreateWindow creates a window and OpenGL/Vulkan-capable context (per hints). The returned *Window is a Go wrapper registered for callbacks; call Destroy when done. Pass nil monitor for windowed mode and nil share for no context sharing.

func CurrentContext

func CurrentContext() *Window

CurrentContext returns the window whose OpenGL or OpenGL ES context is current.

func (*Window) ClipboardString

func (w *Window) ClipboardString() string

ClipboardString returns the contents of the system clipboard.

func (*Window) ContentScale

func (w *Window) ContentScale() (xscale, yscale float32)

ContentScale returns the content scale of the window.

func (*Window) CursorPos

func (w *Window) CursorPos() (x, y float64)

CursorPos returns the position of the cursor relative to the content area.

func (*Window) Destroy

func (w *Window) Destroy()

Destroy destroys the window, clears its callbacks and user data, and unregisters it from the handle map. The Window must not be used afterward.

func (*Window) Focus

func (w *Window) Focus()

Focus brings the window to front and sets input focus.

func (*Window) FrameSize

func (w *Window) FrameSize() (left, top, right, bottom int32)

FrameSize returns the size of the window frame edges.

func (*Window) FramebufferSize

func (w *Window) FramebufferSize() (w2, h int32)

FramebufferSize returns the size of the framebuffer.

func (*Window) GetAttrib

func (w *Window) GetAttrib(attrib Hint) int32

GetAttrib returns the value of a window attribute.

func (*Window) GetInputMode

func (w *Window) GetInputMode(mode InputMode) int32

GetInputMode returns the value of an input option for the window.

func (*Window) Hide

func (w *Window) Hide()

Hide hides the window.

func (*Window) Iconify

func (w *Window) Iconify()

Iconify iconifies the window.

func (*Window) Key

func (w *Window) Key(key Key) Action

Key returns the last reported state of a keyboard key.

func (*Window) MakeContextCurrent

func (w *Window) MakeContextCurrent()

MakeContextCurrent makes the window's OpenGL or OpenGL ES context current.

func (*Window) Maximize

func (w *Window) Maximize()

Maximize maximizes the window.

func (*Window) Monitor

func (w *Window) Monitor() *Monitor

Monitor returns the monitor the window is fullscreen on, or nil.

func (*Window) MouseButton

func (w *Window) MouseButton(button MouseButton) Action

MouseButton returns the last reported state of a mouse button.

func (*Window) Opacity

func (w *Window) Opacity() float32

Opacity returns the opacity of the window.

func (*Window) Pos

func (w *Window) Pos() (x, y int32)

Pos returns the position of the window's content area.

func (*Window) RequestAttention

func (w *Window) RequestAttention()

RequestAttention requests user attention to the window.

func (*Window) Restore

func (w *Window) Restore()

Restore restores the window if it was iconified or maximized.

func (*Window) SetAspectRatio

func (w *Window) SetAspectRatio(numer, denom int32)

SetAspectRatio sets the required aspect ratio of the content area.

func (*Window) SetAttrib

func (w *Window) SetAttrib(attrib Hint, value int32)

SetAttrib sets the value of a window attribute.

func (*Window) SetCharCallback

func (w *Window) SetCharCallback(cb CharFunc) CharFunc

SetCharCallback sets the Unicode character callback and returns the previous one.

func (*Window) SetCharModsCallback

func (w *Window) SetCharModsCallback(cb CharModsFunc) CharModsFunc

SetCharModsCallback sets the character-with-modifiers callback and returns the previous one.

func (*Window) SetClipboardString

func (w *Window) SetClipboardString(str string)

SetClipboardString sets the system clipboard to the specified string.

func (*Window) SetCloseCallback

func (w *Window) SetCloseCallback(cb WindowCloseFunc) WindowCloseFunc

SetCloseCallback sets the close callback and returns the previous one.

func (*Window) SetContentScaleCallback

func (w *Window) SetContentScaleCallback(cb WindowContentScaleFunc) WindowContentScaleFunc

SetContentScaleCallback sets the content scale callback and returns the previous one.

func (*Window) SetCursor

func (w *Window) SetCursor(cursor *Cursor)

SetCursor sets the cursor image used when the cursor is over the content area. Pass nil to restore the default arrow cursor.

func (*Window) SetCursorEnterCallback

func (w *Window) SetCursorEnterCallback(cb CursorEnterFunc) CursorEnterFunc

SetCursorEnterCallback sets the cursor enter/leave callback and returns the previous one.

func (*Window) SetCursorPos

func (w *Window) SetCursorPos(x, y float64)

SetCursorPos sets the position of the cursor relative to the content area.

func (*Window) SetCursorPosCallback

func (w *Window) SetCursorPosCallback(cb CursorPosFunc) CursorPosFunc

SetCursorPosCallback sets the cursor position callback and returns the previous one.

func (*Window) SetDropCallback

func (w *Window) SetDropCallback(cb DropFunc) DropFunc

SetDropCallback sets the path drop callback and returns the previous one.

func (*Window) SetFocusCallback

func (w *Window) SetFocusCallback(cb WindowFocusFunc) WindowFocusFunc

SetFocusCallback sets the focus callback and returns the previous one.

func (*Window) SetFramebufferSizeCallback

func (w *Window) SetFramebufferSizeCallback(cb FramebufferSizeFunc) FramebufferSizeFunc

SetFramebufferSizeCallback sets the framebuffer size callback and returns the previous one.

func (*Window) SetIcon

func (w *Window) SetIcon(images []Image)

SetIcon sets the window icon from one or more images.

func (*Window) SetIconifyCallback

func (w *Window) SetIconifyCallback(cb WindowIconifyFunc) WindowIconifyFunc

SetIconifyCallback sets the iconify callback and returns the previous one.

func (*Window) SetInputMode

func (w *Window) SetInputMode(mode InputMode, value int32)

SetInputMode sets an input option for the window.

func (*Window) SetKeyCallback

func (w *Window) SetKeyCallback(cb KeyFunc) KeyFunc

SetKeyCallback sets the key callback and returns the previous one.

func (*Window) SetMaximizeCallback

func (w *Window) SetMaximizeCallback(cb WindowMaximizeFunc) WindowMaximizeFunc

SetMaximizeCallback sets the maximize callback and returns the previous one.

func (*Window) SetMonitor

func (w *Window) SetMonitor(monitor *Monitor, xpos, ypos, width, height, refreshRate int32)

SetMonitor sets the monitor and video mode for fullscreen or windowed mode. Pass nil monitor to switch back to windowed mode.

func (*Window) SetMouseButtonCallback

func (w *Window) SetMouseButtonCallback(cb MouseButtonFunc) MouseButtonFunc

SetMouseButtonCallback sets the mouse button callback and returns the previous one.

func (*Window) SetOpacity

func (w *Window) SetOpacity(opacity float32)

SetOpacity sets the opacity of the window.

func (*Window) SetPos

func (w *Window) SetPos(x, y int32)

SetPos sets the position of the window's content area.

func (*Window) SetPosCallback

func (w *Window) SetPosCallback(cb WindowPosFunc) WindowPosFunc

SetPosCallback sets the window position callback and returns the previous one. Pass nil to remove. All Set*Callback methods on Window share this replace semantics.

func (*Window) SetRefreshCallback

func (w *Window) SetRefreshCallback(cb WindowRefreshFunc) WindowRefreshFunc

SetRefreshCallback sets the refresh callback and returns the previous one.

func (*Window) SetScrollCallback

func (w *Window) SetScrollCallback(cb ScrollFunc) ScrollFunc

SetScrollCallback sets the scroll callback and returns the previous one.

func (*Window) SetShouldClose

func (w *Window) SetShouldClose(v bool)

SetShouldClose sets whether the window should be closed.

func (*Window) SetSize

func (w *Window) SetSize(width, height int32)

SetSize sets the size of the window's content area.

func (*Window) SetSizeCallback

func (w *Window) SetSizeCallback(cb WindowSizeFunc) WindowSizeFunc

SetSizeCallback sets the window size callback and returns the previous one.

func (*Window) SetSizeLimits

func (w *Window) SetSizeLimits(minW, minH, maxW, maxH int32)

SetSizeLimits sets the minimum and maximum size limits of the content area.

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

SetTitle sets the window title.

func (*Window) SetUserPointer

func (w *Window) SetUserPointer(ptr any)

SetUserPointer stores an arbitrary Go value on this window. Unlike glfwSetWindowUserPointer, the value is kept only on the Go wrapper so the garbage collector can track it. Pass nil to clear.

func (*Window) ShouldClose

func (w *Window) ShouldClose() bool

ShouldClose reports whether the window has been requested to close.

func (*Window) Show

func (w *Window) Show()

Show makes the window visible.

func (*Window) Size

func (w *Window) Size() (w2, h int32)

Size returns the size of the window's content area.

func (*Window) SwapBuffers

func (w *Window) SwapBuffers()

SwapBuffers swaps the front and back buffers of the window.

func (*Window) Title

func (w *Window) Title() string

Title returns the window title.

func (*Window) UserPointer

func (w *Window) UserPointer() any

UserPointer returns the value previously passed to SetUserPointer.

type WindowCloseFunc

type WindowCloseFunc func(window *Window)

type WindowContentScaleFunc

type WindowContentScaleFunc func(window *Window, xscale float32, yscale float32)

type WindowFocusFunc

type WindowFocusFunc func(window *Window, focused int32)

type WindowIconifyFunc

type WindowIconifyFunc func(window *Window, iconified int32)

type WindowMaximizeFunc

type WindowMaximizeFunc func(window *Window, maximized int32)

type WindowPosFunc

type WindowPosFunc func(window *Window, xpos int32, ypos int32)

type WindowRefreshFunc

type WindowRefreshFunc func(window *Window)

type WindowSizeFunc

type WindowSizeFunc func(window *Window, width int32, height int32)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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