0

我试图让 go-gl 在 Windows 中工作,但加载 gl 函数似乎出了点问题。这是我正在运行的代码:

package main

import (
    "log"
    "runtime"

    "github.com/go-gl/gl/v3.3-core/gl"
    "github.com/go-gl/glfw/v3.3/glfw"
)

func init() {
    runtime.LockOSThread()
}

func main() {
    if err := glfw.Init(); err != nil {
        log.Fatal(err)
    }
    defer glfw.Terminate()

    w, err := glfw.CreateWindow(800, 600, "Glfw window", nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    w.MakeContextCurrent()
    for !w.ShouldClose() {
        gl.ClearColor(0, 0.1, 0, 1.0)
        gl.Clear(gl.COLOR_BUFFER_BIT)
        w.SwapBuffers()
        glfw.PollEvents()
    }
}

这失败了:

Exception 0xc0000005 0x8 0x0 0x0
PC=0x0
signal arrived during external code execution

runtime.cgocall(0x7ff75869c4b0, 0xc000107f18)
        C:/Program Files/Go/src/runtime/cgocall.go:156 +0x4a fp=0xc000107ef0 sp=0xc000107eb8 pc=0x7ff758603a4a
github.com/go-gl/gl/v3.3-core/gl._Cfunc_glowClearColor(0x0, 0x0, 0x3dcccccd, 0x0, 0x3f800000)
        _cgo_gotypes.go:3907 +0x52 fp=0xc000107f18 sp=0xc000107ef0 pc=0x7ff758696cb2
github.com/go-gl/gl/v3.3-core/gl.ClearColor(...)
        C:/Users/rwsim/go/pkg/mod/github.com/go-gl/gl@v0.0.0-20210905235341-f7a045908259/v3.3-core/gl/package.go:8974
main.main()
        C:/Users/rwsim/go/src/github.com/decitrig/hellogl/wingl.go:27 +0x109 fp=0xc000107f80 sp=0xc000107f18 pc=0x7ff75869bae9
runtime.main()
        C:/Program Files/Go/src/runtime/proc.go:255 +0x217 fp=0xc000107fe0 sp=0xc000107f80 pc=0x7ff758637497
runtime.goexit()
        C:/Program Files/Go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000107fe8 sp=0xc000107fe0 pc=0x7ff75865e861
rax     0x0
rbx     0xc000107f18
rcx     0xc000107f18
rdi     0xc000107f18
rsi     0x7ff7587c5200
rbp     0xc000107ee0
rsp     0x52e5fffa68
r8      0x7ff7587c53a0
r9      0x0
r10     0x8
r11     0x10
r12     0xc000107e08
r13     0x1
r14     0xc00003c000
r15     0xa
rip     0x0
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b

由于 PC 是0x0,我猜有些东西无法加载 OpenGL 函数指针,因此调用glClear是 segfaulting 。一切都编译得很好,它只是不能调用opengl。

4

1 回答 1

1

啊哈,一个愚蠢的错误。错过来电gl.Init()

于 2021-09-20T02:18:42.747 回答