使用Go调用OpenGL

11

我正在尝试在Go程序中使用OpenGL。我认为所有必要的部分都已经就位,但我仍然无法将其运行起来。

我的C编译器是mingw的64位版本。它已经加入了%PATH%环境变量,并且我已经通过文档中的随机数例子验证了它的工作状态。

我通过将bin、lib和include文件夹复制到mingw-w64安装中的\mingw\x86_64-w64-mingw32等效路径下,安装了64位GLEW 1.9.0。

当我尝试运行go get github.com/go-gl/gl时,Go给出以下回复:

In file included from attriblocation.go:7:0:
gl.h:5:25: error: enumerator value for '__cgo_enum__5' is not an integer constant
 #define GLEW_GET_FUN(x) (*x)
                         ^
d:\programs\mingw64\x86_64-w64-mingw32\include\gl\glew.h:1956:26: note: in expansion of macro 'GLEW_GET_FUN'
 #define glVertexAttrib3f GLEW_GET_FUN(__glewVertexAttrib3f)
                          ^
gl.h:5:25: error: enumerator value for '__cgo_enum__6' is not an integer constant
 #define GLEW_GET_FUN(x) (*x)

这些错误在值达到__cgo_enum__15之前以类似的方式继续出现。对于每个条目,我还会从Go方面得到一些匹配错误。

有任何想法可以让这个工作起来吗?

编辑:以下是来自Go方面的“匹配”日志。

attriblocation.go:42:2: error: initializer element is not constant
 func (indx AttribLocation) Attrib4fv(values *[4]float32) {
  ^
attriblocation.go:42:2: error: (near initialization for '__cgodebug_data[5]')
attriblocation.go:43:2: error: initializer element is not constant
  C.glVertexAttrib4fv(C.GLuint(indx), (*C.GLfloat)(&values[0]))
  ^
attriblocation.go:43:2: error: (near initialization for '__cgodebug_data[6]')
attriblocation.go:44:2: error: initializer element is not constant
 }

每个__cgodebug_data[] 5-15都有一个。

编辑2:我被要求附上一些日志。这是使用GCC 4.8编译时发生的情况,以及这是我在4.7和4.6中得到的情况


你所说的匹配错误是什么意思?你能把它们也发出来吗? - nemo
我运行了它,但没有看到任何新的失败。如果您感兴趣,这是完整的日志:http://pastebin.com/2EXghL1k - Corey Larson
哦,谢谢提供的信息!我会去查看一下旧版本是否支持Windows上的Go语言。 - Corey Larson
我尝试了较旧版本的编译器(保持了相同版本的GLEW),仍然存在问题。我已经在帖子正文中附上了新的日志。 - Corey Larson
1
记录一下,我在64位Linux上使用Go 1.1也遇到了同样的问题。所以这不是MingW的问题。 - jimt
显示剩余4条评论
1个回答

3

1
这实际上是Go语言本身的缺陷,而不是Go-GL的问题。由于编译器之间的通信问题,Go-GL无法解决该问题。 - pwaller

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接