Using an offset with VBOs in OpenGL

99封情书 提交于 2019-11-30 05:15:06

What do you mean by "start index"? You could mean one of two things:

Start at a different position in the buffer object

Well, just do that. glDrawElements takes an offset into the buffer object for where it starts to pull indices from. So add a value to that.

glDrawElements(renderFlag, 20, GL_UNSIGNED_INT, (void*)(ixStart * sizeof(GLuint)));

Offset the indices you fetch from the buffer

This means that you want to draw the same range of indices, but you want to apply an offset to those index values themselves. So if your index buffer looks like this: (1, 4, 2, 0, 5, ...), and you apply an offset of 20, then it will fetch these indices: (21, 24, 22, 20, 25, ...).

This is done with glDrawElementsBaseVertex. It looks something like this:

glDrawElementsBaseVertex(renderFlag, 20, GL_UNSIGNED_INT, 0, offset);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!