go-gl / gl

Go bindings for OpenGL (generated via glow)
MIT License
1.07k stars 74 forks source link

Retrieve Uniform or Attribute name #67

Closed raedatoui closed 7 years ago

raedatoui commented 7 years ago

I am trying to retrieve the info of attributes and uniforms of an already linked shader. The shader is working and the calls gl.GetActiveAttrib and gl.GetActiveUniform are working as expected. I am just stuck on converting the uint8 type to a Go string

var count int32
var i uint32
var s, b, l int32
var t uint32
var n uint8

gl.GetProgramiv(program, gl.ACTIVE_UNIFORMS, &count)
fmt.Printf("Active Uniforms: %d\n", count)
for i = 0; i < uint32(count); i++ {
    gl.GetActiveUniform(program, i, b, &l, &s, &t, &n)
    fmt.Println(i, b, l, s, t,  gl.GoStr(&n))
}

gl.GoStr(&n) is returning an empty string. How can I properly convert n to a string? much appreciated!

dmitshur commented 7 years ago

You're not using the OpenGL call properly. Read its documentation:

http://docs.gl/gl2/glGetActiveUniform

Specifically:

You're currently passing it a bufSize value of 0, so of course emptry string is all it can give you.

Look at the example at the bottom of that documentation page. It uses a buffer of size 256. Try that. Something along these lines:

var buf [256]byte
gl.GetActiveUniform(..., len(buf), ..., &buf[0])
s := gl.GoStr(&buf[0])
raedatoui commented 7 years ago

oh doh! thank you!