最近在看看一个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库的例子,想照猫画一下,但是就遇到问题了。
gl.Begin(gl.TRIANGLES) gl.Color3f(1.0,0.0,0.0) //red gl.Vertex3f(0.0,1.0,0.0) gl.Color3f(0.0,0.0) //Green gl.Vertex3f(-1.0,-1.0,1.0) //blue gl.Vertex3f(1.0,0.0) gl.End()
直接运行会报错:
fatal error: unexpected signal during runtime execution
找了很久都找不到为什么会报这个错。
原文链接:https://www.f2er.com/go/189888.html