I've been working through some opengl in golang learning and have the following fragments:
import(
"github.com/go-gl/gl/v3.3-core/gl"
)
vertices := []float32{
// Position // Colors // Texture Coords
1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, // Top Right
1.0, -1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, // Bottom Right
-1.0, -1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, // Bottom Left
-1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, // Top Left
}
vlen := int32(len(vertices) * 4 / 4)
var offset uint32 = 0
//position
gl.VertexAttribPointer(0, 3, gl.FLOAT, false, vlen, nil)
gl.EnableVertexAttribArray(0)
//color
offset = offset + 12
gl.VertexAttribPointer(1, 3, gl.FLOAT, false, vlen, unsafe.Pointer(&offset))
gl.EnableVertexAttribArray(1)
offset = 0
So I get my basic square I've been working on -- nil in the 5th position parameter for VertexAttribPointer for position seems to work, but I get nothing with color in the larger program. And if I try to specify an offset unsafe pointer of 0 for poistion I get nothing but empty space.
Specifying an unsafe pointer there is something I'm not understanding at the moment -- I think I need to specify where in vertices the offset for color is, but I'm not following. I am not sure vlen is correct either. Any input appreciated.
EDIT:
Self found solution -- what I needed was gl.PtrOffset, which I wasnt aware of when initially creating the quetion.
gl.VertexAttribPointer(1, 3, gl.FLOAT, false, vlen, gl.PtrOffset(offset))