Go Bindings for GLFW 3
- ATTENTION: As of GLFW 3.1 we break API. See Changelog below.
- See here for documentation.
- You can help by submitting examples to go-gl/examples.
Remarks
- Some functions -which are marked in the documentation- can be called only from the main thread. You need to use runtime.LockOSThread() to arrange that main() runs on main thread.
- Installation is easy, just
go get github.com/go-gl/glfw3
and be done (GLFW sources are included so you don't have to build GLFW on your own)! - Go 1.4 is required on Windows (otherwise you must use MinGW v4.8.1 exactly, see Go issue 8811).
Example
package main
import (
"runtime"
glfw "github.com/go-gl/glfw3"
)
func init() {
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
The revision of GLFW C library used is listed in GLFW_C_REVISION.txt file.
- Type glfw3.GLFWError renamed to just glfw3.Error.
- Method window.SetCharacterCallback renamed to window.SetCharCallback.
- Method window.SetCharacterModsCallback renamed to window.SetCharModsCallback.
- Added
Floating
and AutoIconify
window hints. - Easy
go get
installation (GLFW source code included in-repo and compiled in so you don't have to build GLFW on your own first and you don't have to distribute shared libraries). - SetErrorCallback This function is removed. The 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).
- Init Returns an error instead of bool.
- GetTime Returns an error.
- GetCurrentContext No longer returns an error.
- GetJoystickAxes No longer returns an error.
- GetJoystickButtons No longer returns an error.
- GetJoystickName No longer returns an error.
- window.GetMonitor No longer returns an error.
- window.GetAttribute Returns an error.
- window.SetCharCallback Accepts rune instead of uint.
- window.SetDropCallback added.
- window.SetCharModsCallback added.
- PostEmptyEvent added.
- Native window and context handlers added.
- Constant ApiUnavailable changed to APIUnavailable.
- Constant ClientApi changed to ClientAPI.
- Constant OpenglForwardCompatible changed to OpenGLForwardCompatible.
- Constant OpenglDebugContext changed to OpenGLDebugContext.
- Constant OpenglProfile changed to OpenGLProfile.
- Constant SrgbCapable changed to SRGBCapable.
- Constant OpenglApi changed to OpenGLAPI.
- Constant OpenglEsApi changed to OpenGLESAPI.
- Constant OpenglAnyProfile changed to OpenGLAnyProfile.
- Constant OpenglCoreProfile changed to OpenGLCoreProfile.
- Constant OpenglCompatProfile changed to OpenGLCompatProfile.