最近在看看一个Golang的项目,里面使用了GLFW和GL来写UI,之前从来没有接触过这两个库,安装官方文档写了一个例子。
package main
import (
"runtime"
"github.com/go-gl/glfw/v3.1/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()
}
}
这个例子可以直接run,一切都很正常。后来看到一个C库的例子ÿ