1
\$\begingroup\$

I have a Renderer component which can render a Scene. Assume the scene is just a container for Renderable objects. A Renderable is composed by a Geometry and a Material. I call that a Mesh. When rendering the multiple renderables, that's essentially what I do, for each renderable:

var (
    vbo      uint32
    ibo      *opengl.IndexBuffer
    geometry = renderable.GetGeometry()
)

gl.BindVertexArray(r.vao)

gl.GenBuffers(1, &vbo)
gl.BindBuffer(gl.ARRAY_BUFFER, vbo)
gl.BufferData(gl.ARRAY_BUFFER, int(unsafe.Sizeof(geometry.GetVertices())*VertexSize), nil, gl.DYNAMIC_DRAW)

ibo = opengl.NewIndexBuffer(geometry.GetIndices(), uint32(len(geometry.GetIndices())))
ibo.Bind()

gl.DrawElements(gl.TRIANGLES, int32(ibo.Count), gl.UNSIGNED_INT, gl.Ptr(geometry.GetIndices()))

ibo.Unbind()
gl.BindBuffer(gl.ARRAY_BUFFER, 0)
gl.BindVertexArray(0)

opengl.IndexBuffer is my implementation of an index buffer. It simply does:

gl.GenBuffers(1, &indexBuffer.ID)
gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer.ID)
gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, int(count)*4, gl.Ptr(&data[0]), gl.STATIC_DRAW)

However, I can't seem to draw my geometry. What am I doing wrong?

\$\endgroup\$
  • 1
    \$\begingroup\$ Is this your actual render function (memory leak and all) or is it code culled from multiple functions? \$\endgroup\$ – Maximus Minimus Jul 16 '17 at 13:01
  • \$\begingroup\$ It's just a first version. I'm aware of the leaks and it's not necessarily one function. \$\endgroup\$ – Daniel Ribeiro Jul 16 '17 at 14:08
  • \$\begingroup\$ This is actually important; ignore the leaks for now and show the actual code, because your index buffer unbinding could be what's at fault depending on the split between creation code and drawing code. \$\endgroup\$ – Maximus Minimus Jul 16 '17 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.