【发布时间】:2013-10-06 18:52:06
【问题描述】:
我正在关注一些初学者的 OpenGL 教程,对这段代码的 sn-p 有点困惑:
glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObject); //Bind GL_ARRAY_BUFFER to our handle
glEnableVertexAttribArray(0); //?
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); //Information about the array, 3 points for each vertex, using the float type, don't normalize, no stepping, and an offset of 0. I don't know what the first parameter does however, and how does this function know which array to deal with (does it always assume we're talking about GL_ARRAY_BUFFER?
glDrawArrays(GL_POINTS, 0, 1); //Draw the vertices, once again how does this know which vertices to draw? (Does it always use the ones in GL_ARRAY_BUFFER)
glDisableVertexAttribArray(0); //?
glBindBuffer(GL_ARRAY_BUFFER, 0); //Unbind
我不明白 glDrawArrays 如何知道要绘制哪些顶点,以及与 glEnableVertexAttribArray 相关的所有内容。有人能说明一下情况吗?
【问题讨论】:
标签: opengl graphics rendering vertex