C++ OpenGL如何知道基于GL_数组_缓冲区绘制顶点的位置?
例如,我有以下代码:C++ OpenGL如何知道基于GL_数组_缓冲区绘制顶点的位置?,c++,opengl,buffer,vbo,vao,C++,Opengl,Buffer,Vbo,Vao,例如,我有以下代码: //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,
//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_数组_缓冲区的内容是关于位置的信息,而不是关于颜色的信息,例如?如果
GL_顶点
可用(即不是核心配置文件),则规范会调用该位置和顶点属性0别名
摘自(第401/1005页):
将“常规顶点”属性设置为零指定顶点,如下所示:
如第10.7.2节所述。设置任何其他常规顶点
属性更新属性的当前值。没有
顶点属性的当前值为零
没有。但是你的着色器是这样的,而且两者是绑定在一起的。问题是我能够用代码画一个三角形,而不用着色器。这就是我感到困惑的原因。我不知道驱动程序的详细信息,但我希望存在某种默认情况,即原语首先假定它是位置组件。@Robinson:每个驱动程序可能都有自己的,但NVidia对此相当一致。通常,在没有着色器的情况下使用常规顶点属性会带来麻烦。通常情况下,属性0似乎与固定的函数位置混淆。但这并不适用于所有平台。