繁体   English   中英

OpenGL如何知道应基于GL_ARRAY_BUFFER将顶点绘制到什么位置?

[英]How does OpenGL know to what position it should draw the vertices based on the GL_ARRAY_BUFFER?

例如,我有以下代码:

//Create a vbo and bind it to the GL_ARRAY_BUFFER
glGenBuffers(1, &positionBufferObject);    
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);

//vertexPosition is an array of floats that stores the position of 3 vertices (x, y, z, w)
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);

//Enable the vbo at index 0 of the vao (assuming I have stored it previously at index 0)
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);

//Finally draw the triangle
glDrawArrays(GL_TRIANGLES, 0, 3);

我的问题是,glDrawArrays()如何知道绑定到GL_ARRAY_BUFFER的内容是指位置信息,而不是颜色信息?

如果gl_Vertex可用(即没有核心配置文件),则规范会调用该位置和顶点属性0别名。

gl 4.5兼容性配置文件规范 (第401/1005页):

将通用顶点属性设置为零会指定一个顶点,如10.7.2节所述。 设置任何其他通用顶点属性将更新该属性的当前值。 顶点属性零没有当前值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM