Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenGL from Go

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.

like image 628
Corey Larson Avatar asked May 07 '13 06:05

Corey Larson


1 Answers

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.

like image 137
Corey Larson Avatar answered Sep 18 '22 12:09

Corey Larson