This is a creation in Article, where the information may have evolved or changed.
Recently looking at a Golang project, which uses GLFW and GL to write the UI, has never been in contact with these two libraries before, the installation of official documents wrote an example.
Package Mainimport ( "Runtime", " GITHUB.COM/GO-GL/GLFW/V3.1/GLFW") func init () { //This was needed to arrange That main () runs on main thread. See documentation for functions that is only allowed to is 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 () }}
This example can run directly, everything is normal. Later saw a C library example, want to picture a cat, but encountered problems.
In this example, the following code is added:
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, 1.0, 0.0)//green gl. vertex3f ( -1.0, -1.0, 0.0) gl. color3f (0.0, 0.0, 1.0)//blue gl. vertex3f (1.0, -1.0, 0.0) gl. End ()
Direct operation will be error:
Fatal error:unexpected signal during runtime execution
I've been looking for a long time to find out why I reported this mistake. Suddenly realize that go is an object-oriented language, GLFW all use the initialized function, GL will be the same, add initialization code after the normal. It's really a rookie mistake.