Golang glfw中使用opengl庫的問題

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

最近在看看一個Golang的項目,裡面使用了GLFW和GL來寫UI,之前從來沒有接觸過這兩個庫,安裝官方文檔寫了一個例子。

package mainimport (    "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, 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()

直接運行會報錯:

fatal error: unexpected signal during runtime execution
找了很久都找不到為什麼會報這個錯。突然意識到go是物件導向的語言,glfw都使用了初始化的函數,gl會不會也一樣了,添加初始化代碼之後就正常了。真的是才會新手犯的錯啊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.