使用Go语言调用OpenGL

huangapple go评论85阅读模式
英文:

Using OpenGL from Go

问题

我正在尝试在Go程序中使用OpenGL。我认为我已经准备好了所有的部分,但是我还不能完全运行它。

我的C编译器是mingw的64位版本。它在我的%PATH%变量中,并且我已经通过cgo文档中的随机数示例验证了它的工作。

我通过将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时得到的结果

英文:

I am trying to use OpenGL from within a Go program. I think I have all of the pieces in place, but I am still not quite able to get it running.

My C compiler is the 64-bit version of mingw. It is in my %PATH% variable, and I have verified it working with the random number example in the cgo documentation.

I installed the 64-bit GLEW 1.9.0 by coping the bin, lib, and include folders to the \mingw\x86_64-w64-mingw32 equivalents in my mingw-w64 installation.

When I try and run go get github.com/go-gl/gl, go replies with the following:

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)

These errors continue in a similar fashion for values up to __cgo_enum__15. I also get some matching errors coming from the Go side of things for each entry.

Any ideas on what I am missing to get this to work?

Edit: Here are the 'matching' logs from the Go side of things.

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
 }

There is one for every __cgodebug_data[] 5-15.

Edit 2: I have been asked to attach some logs. Here is what happens when I compile with GCC 4.8, and Here is what I get with 4.7 and 4.6.

答案1

得分: 3

看起来这是Go语言中的一个缺陷,以及C/Go编译器之间的通信方式。解决方法是设置CGO_CFLAGS=-ftrack-macro-expansion=0 go build。你也可以使用go-1.2rc5或更新版本来解决这个问题。这个bug已经在之前的解决方法中关闭

英文:

It looks like it is a defect in Go and how the C/Go compilers communicate with each other. The workaround is to set CGO_CFLAGS=-ftrack-macro-expansion=0 go build. You could also use go-1.2rc5 or newer to fix the issue. This bug has been closed with the previous workarounds/fixes specified.

huangapple
  • 本文由 发表于 2013年5月7日 14:33:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/16412644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定