xcode-select --install
) for required headers and libraries.libgl1-mesa-dev
and xorg-dev
packages.libX11-devel libXcursor-devel libXrandr-devel libXinerama-devel mesa-libGL-devel libXi-devel
packages.go get -u github.com/go-gl/glfw/v3.3/glfw
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.3/glfw
Supported tags are gles1
, gles2
, gles3
and vulkan
. Note that required packages might differ from those listed above; consult your hardware's documentation.
package main import ( "runtime" "github.com/go-gl/glfw/v3.3/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() } }
Window.Handle
can be used to create a Vulkan surface via the this package.Window.GLFWWindow
to Window.Handle
Window.SetAttrib
.Window.RequestAttention
.Window.GetContentScale
.Window.GetOpacity
.Window.SetOpacity
.Window.SetMaximizeCallback
.Window.SetContentScaleCallback
.Monitor.GetWorkarea
.Monitor.GetContentScale
.Monitor.SetUserPointer
.Monitor.GetUserPointer
.InitHint
.RawMouseMotionSupported
GetKeyScancode
.WindowHintString
.GetClipboardString
.SetClipboardString
.Joystick.GetHats
.Joystick.IsGamepad
.Joystick.GetGUID
.Joystick.GetGamepadName
.Joystick.GetGamepadState
.Joystick.SetUserPointer
.Joystick.GetUserPointer
.UpdateGamepadMappings
.SetX11SelectionString
.GetX11SelectionString
.ModCapsLock
.ModNumLock
LockKeyMods
.RawMouseMotion
.Hovered
.CenterCursor
.TransparentFramebuffer
.FocusOnShow
.ScaleToMonitor
.JoystickHatButtons
.CocoaChdirResources
.CocoaMenubar
.TransparentFramebuffer
.OSMesaContextAPI
.CocoaGraphicsSwitching
.CocoaRetinaFramebuffer
.CocoaFrameNAME
.X11ClassName
.X11InstanceName
.MonitorEvent
renamed to PeripheralEvent
for reuse with joystick events.Joystick.GetButtons
Returns []Action
instead of []byte
.SetMonitorCallback
Returns MonitorCallback
.Focus
No longer returns an error.Iconify
No longer returns an error.Maximize
No longer returns an error.Restore
No longer returns an error.GetClipboardString
No longer returns an error.go get
installation. 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.Window.SetSizeLimits
.Window.SetAspectRatio
.Window.SetMonitor
.Window.Maximize
.Window.SetIcon
.Window.Focus
.GetKeyName
.VulkanSupported
.GetTimerValue
.GetTimerFrequency
.WaitEventsTimeout
.SetJoystickCallback
.Maximized
.NoAPI
.NativeContextAPI
.EGLContextAPI
.Cursor
.Window.SetDropCallback
.Window.SetCharModsCallback
.PostEmptyEvent
.CreateCursor
.CreateStandardCursor
.Cursor.Destroy
.Window.SetCursor
.Window.GetFrameSize
.Floating
.AutoIconify
.ContextReleaseBehavior
.DoubleBuffer
.AnyReleaseBehavior
.ReleaseBehaviorFlush
.ReleaseBehaviorNone
.DontCare
.Window.Iconify
Returns an error.Window.Restore
Returns an error.Init
Returns an error instead of bool
.GetJoystickAxes
No longer returns an error.GetJoystickButtons
No longer returns an error.GetJoystickName
No longer returns an error.GetMonitors
No longer returns an error.GetPrimaryMonitor
No longer returns an error.Monitor.GetGammaRamp
No longer returns an error.Monitor.GetVideoMode
No longer returns an error.Monitor.GetVideoModes
No longer returns an error.GetCurrentContext
No longer returns an error.Window.SetCharCallback
Accepts rune
instead of uint
.Error
.SetErrorCallback
.NotInitialized
.NoCurrentContext
.InvalidEnum
.InvalidValue
.OutOfMemory
.PlatformError
.KeyBracket
.Window.SetCharacterCallback
to Window.SetCharCallback
.Window.GetCursorPosition
to GetCursorPos
.Window.SetCursorPosition
to SetCursorPos
.CursorPositionCallback
to CursorPosCallback
.Window.SetCursorPositionCallback
to SetCursorPosCallback
.VideoMode
to VidMode
.Monitor.GetPosition
to Monitor.GetPos
.Window.GetPosition
to Window.GetPos
.Window.SetPosition
to Window.SetPos
.Window.GetAttribute
to Window.GetAttrib
.Window.SetPositionCallback
to Window.SetPosCallback
.PositionCallback
to PosCallback
.Cursor
to CursorMode
.StickyKeys
to StickyKeysMode
.StickyMouseButtons
to StickyMouseButtonsMode
.ApiUnavailable
to APIUnavailable
.ClientApi
to ClientAPI
.OpenglForwardCompatible
to OpenGLForwardCompatible
.OpenglDebugContext
to OpenGLDebugContext
.OpenglProfile
to OpenGLProfile
.SrgbCapable
to SRGBCapable
.OpenglApi
to OpenGLAPI
.OpenglEsApi
to OpenGLESAPI
.OpenglAnyProfile
to OpenGLAnyProfile
.OpenglCoreProfile
to OpenGLCoreProfile
.OpenglCompatProfile
to OpenGLCompatProfile
.KeyKp...
to KeyKP...
.