Issues with OpenGL libraries in Golang GLFW

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.