Glfw
Go bindings for GLFW 3
Install / Use
/learn @go-gl/GlfwREADME
GLFW 3.4 for Go
Installation
- GLFW C library source is included and built automatically as part of the Go package. But you need to make sure you have dependencies of GLFW:
- On macOS, you need Xcode or Command Line Tools for Xcode (
xcode-select --install) for required headers and libraries. - On Ubuntu/Debian-like Linux distributions, the default Linux build enables both X11 and Wayland, so you need
libgl1-mesa-dev,xorg-dev,libwayland-dev,libxkbcommon-devandwayland-protocols. - On CentOS/Fedora-like Linux distributions, you need
libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-devel libXxf86vm-develpackages. - On FreeBSD, you need the package
pkgconf. To build for X, you also need the packagexorg; and to build for Wayland, you need the packagewayland. - On NetBSD, to build for X, you need the X11 sets installed. These are included in all graphical installs, and can be added to the system with
sysinst(8)on non-graphical systems. Wayland support is incomplete, due to missing wscons support in upstream GLFW. To attempt to build for Wayland, you need to install thewayland libepoll-shimpackages and set the environment variablePKG_CONFIG_PATH=/usr/pkg/libdata/pkgconfig. - On OpenBSD, you need the X11 sets. These are installed by default, and can be added from the ramdisk kernel at any time.
- See here for full details.
- On macOS, you need Xcode or Command Line Tools for Xcode (
- Go 1.4+ is required on Windows (otherwise you must use MinGW v4.8.1 exactly, see Go issue 8811).
go get -u github.com/go-gl/glfw/v3.4/glfw
OpenGL ES
If your target system only provides an OpenGL ES implementation (true for some ARM boards), you need to link against that implementation. You do this by defining the appropriate build tags, e.g.
go get -u -tags=gles2 github.com/go-gl/glfw/v3.4/glfw
Supported tags are gles1, gles2, gles3 and vulkan.
Note that required packages might differ from those listed above; consult your hardware's documentation.
Usage
package main
import (
"runtime"
"github.com/go-gl/glfw/v3.4/glfw"
)
func init() {
// This is needed to arrange that main() runs on main thread.
// See documentation for functions that are only allowed to be called from the main thread.
runtime.LockOSThread()
}
func main() {
err := glfw.Init()
if err != nil {
panic(err)
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
for !window.ShouldClose() {
// Do OpenGL stuff.
window.SwapBuffers()
glfw.PollEvents()
}
}
Changelog
GLFW 3.4 Specific Changes
- This section is cumulative for the v3.4 branch and includes changes from multiple commits.
- Added support for dynamic runtime switching between X11 and Wayland on Linux.
- Replaced compile-time Wayland icon checking with
glfwGetPlatform(). - Mapped
GLFW_FEATURE_UNAVAILABLEandGLFW_FEATURE_UNIMPLEMENTEDto prevent go panics on unsupported platform features. - Mapped
GLFW_CURSOR_UNAVAILABLEandGLFW_PLATFORM_UNAVAILABLE. - Added function
GetPlatform. - Added function
PlatformSupported. - Added function
InitAllocator. - Added function
InitVulkanLoader. - Added function
GetError. - Added function
GetPhysicalDevicePresentationSupport. - Added function
Window.GetTitle. - Added function
Window.GetCocoaView. - Added hint
MousePassthrough. - Added hint
PositionX. - Added hint
PositionY. - Added hint
ContextDebug. - Added hint
ContextNoError. - Added hint
AnglePlatformType. - Added hint
PlatformHint. - Added hint
ScaleFramebuffer. - Added hint
Win32KeyboardMenu. - Added hint
Win32ShowDefault. - Added hint
WaylandAppID. - Added hint
WaylandLibdecor. - Added hint
X11XcbVulkanSurface. - Added hint value
AnyPosition. - Added hint value
WaylandPreferLibdecor. - Added hint value
WaylandDisableLibdecor. - Added cursor mode value
CursorCaptured. GLFW_UNLIMITED_MOUSE_BUTTONSis not mapped because it is not present in the vendored GLFW C revision used by this package.- Added multiple new standard cursors like
PointingHandCursor,ResizeEWCursor, etc. - Added
AnglePlatformType*hint values for configuring ANGLE rendering backend. - Added
Platformtype and values (AnyPlatform,PlatformWin32,PlatformCocoa,PlatformWayland,PlatformX11,PlatformNull).
GLFW 3.3 Specific Changes
- Joystick functions now uses receivers instead of passing the joystick ID as argument.
- Vulkan methods are intentionally not implemented.
Window.Handlecan be used to create a Vulkan surface via the this package.
- Renamed
Window.GLFWWindowtoWindow.Handle - Added function
Window.SetAttrib. - Added function
Window.RequestAttention. - Added function
Window.GetContentScale. - Added function
Window.GetOpacity. - Added function
Window.SetOpacity. - Added function
Window.SetMaximizeCallback. - Added function
Window.SetContentScaleCallback. - Added function
Monitor.GetWorkarea. - Added function
Monitor.GetContentScale. - Added function
Monitor.SetUserPointer. - Added function
Monitor.GetUserPointer. - Added function
InitHint. - Added function
RawMouseMotionSupported - Added function
GetKeyScancode. - Added function
WindowHintString. - Added function
GetClipboardString. - Added function
SetClipboardString. - Added function
Joystick.GetHats. - Added function
Joystick.IsGamepad. - Added function
Joystick.GetGUID. - Added function
Joystick.GetGamepadName. - Added function
Joystick.GetGamepadState. - Added function
Joystick.SetUserPointer. - Added function
Joystick.GetUserPointer. - Added function
UpdateGamepadMappings. - Added function
SetX11SelectionString. - Added function
GetX11SelectionString. - Added gamepad button IDs.
- Added gamepad axis IDs.
- Added joystick hat state IDs.
- Added ModifierKey
ModCapsLock. - Added ModifierKey
ModNumLock - Added InputMode
LockKeyMods. - Added InputMode
RawMouseMotion. - Added hint
Hovered. - Added hint
CenterCursor. - Added hint
TransparentFramebuffer. - Added hint
FocusOnShow. - Added hint
ScaleToMonitor. - Added hint
JoystickHatButtons. - Added hint
CocoaChdirResources. - Added hint
CocoaMenubar. - Added hint
TransparentFramebuffer. - Added hint value
OSMesaContextAPI. - Added hint value
CocoaGraphicsSwitching. - Added hint value
CocoaRetinaFramebuffer. - Added string hint value
CocoaFrameNAME. - Added string hint value
X11ClassName. - Added string hint value
X11InstanceName. MonitorEventrenamed toPeripheralEventfor reuse with joystick events.Joystick.GetButtonsReturns[]Actioninstead of[]byte.SetMonitorCallbackReturnsMonitorCallback.FocusNo longer returns an error.IconifyNo longer returns an error.MaximizeNo longer returns an error.RestoreNo longer returns an error.GetClipboardStringNo longer returns an error.
GLFW 3.2 Specific Changes
- Easy
go getinstallation. GLFW source code is now included in-repo and compiled in so you don't have to build GLFW on your own and distribute shared libraries. The revision of GLFW C library used is listed in GLFW_C_REVISION.txt file. - The error callback is now set internally. Functions return an error with corresponding code and description (do a type assertion to glfw3.Error for accessing the variables) if the error is recoverable. If not a panic will occur.
- Added function
Window.SetSizeLimits. - Added function
Window.SetAspectRatio. - Added function
Window.SetMonitor. - Added function
Window.Maximize. - Added function
Window.SetIcon. - Added function
Window.Focus. - Added function
GetKeyName. - Added function
VulkanSupported. - Added function
GetTimerValue. - Added function
GetTimerFrequency. - Added function
WaitEventsTimeout. - Added function
SetJoystickCallback. - Added window hint
Maximized. - Added hint
NoAPI. - Added hint
NativeContextAPI. - Added hint
EGLContextAPI.
GLFW 3.1 Specific Changes
- Added type
Cursor. - Added function
Window.SetDropCallback. - Added function
Window.SetCharModsCallback. - Added function
PostEmptyEvent. - Added function
CreateCursor. - Added function
CreateStandardCursor. - Added function
Cursor.Destroy. - Added function
Window.SetCursor. - Added function
Window.GetFrameSize. - Added window hint
Floating. - Added window hint
AutoIconify. - Added window hint
ContextReleaseBehavior. - Added window hint
DoubleBuffer. - Added hint value
AnyReleaseBehavior. - Added hint value
ReleaseBehaviorFlush. - Added hint value
ReleaseBehaviorNone. - Added hint value
DontCare.
API changes
Window.IconifyReturns an error.Window.RestoreReturns an error.InitReturns an error instead ofbool.GetJoystickAxesNo longer returns an error.GetJoystickButtonsNo longer returns an error.GetJoystickNameNo longer returns an error.GetMonitorsNo longer returns an error.GetPrimaryMonitorNo longer returns an error.Monitor.GetGammaRampNo longer returns an error.Monitor.GetVideoModeNo longer returns an error.Monitor.GetVideoModesNo longer returns an error.GetCurrentContextNo longer returns an error.Window.SetCharCallbackAcceptsruneins
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
349.2kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
