drtj40036 2013-05-07 06:33
浏览 142
已采纳

从Go使用OpenGL

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条回答 默认 最新

  • duanboshe0001 2013-05-20 14:20
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题