Opengl es glvertexattributepointer解释

Opengl es glvertexattributepointer解释,opengl-es,vertex-buffer,Opengl Es,Vertex Buffer,我正在跟踪 我对他使用的glvertexattributepointer感到困惑,希望有人能解释他为什么像他那样设置参数。专门用于glvertexattributepointer中最后一个参数的sizeof()。sizeof与数据偏移量的关系如何 下面是顶点结构: typedef struct{ float Position[3]; float Color[4]; } Vertex; 以及顶点和索引数据代码: const Vertex Vertices[] = { {{1, -1, 0}, {

我正在跟踪

我对他使用的
glvertexattributepointer
感到困惑,希望有人能解释他为什么像他那样设置参数。专门用于
glvertexattributepointer
中最后一个参数的
sizeof()
sizeof
与数据偏移量的关系如何

下面是顶点结构:

typedef struct{
float Position[3];
float Color[4];
}
Vertex;
以及顶点和索引数据代码:

const Vertex Vertices[] = {
{{1, -1, 0}, {1, 0, 0, 1}},
{{1, 1, 0}, {1, 0, 0, 1}},
{{-1, 1, 0}, {0, 1, 0, 1}},
{{-1, -1, 0}, {0, 1, 0, 1}},
{{1, -1, -1}, {1, 0, 0, 1}},
{{1, 1, -1}, {1, 0, 0, 1}},
{{-1, 1, -1}, {0, 1, 0, 1}},
{{-1, -1, -1}, {0, 1, 0, 1}}
};

const GLubyte Indices[] = {
 // Front
 0, 1, 2,
2, 3, 0,
// Back
4, 6, 5,
4, 7, 6,
// Left
2, 7, 3,
7, 6, 2,
// Right
0, 4, 1,
4, 1, 5,
// Top
6, 2, 1,
1, 6, 5,
// Bottom
0, 3, 7,
0, 7, 4
};
请解释一下为什么参数设置得像是整个
sizeof
一样


谢谢

他正在使用vbo。因此,基本上,传递顶点结构的大小设置步幅。Ie:在那里可以找到下一个顶点数据

想象一下包含所有顶点结构的线性集合的VBO。第一个开始于0(在VBO中),下一个开始于sizeof(顶点),然后是sizeof(顶点)*2,以此类推


“位置”位于结构的开头,因此不需要到结构中的偏移量(因此,第6个参数为0,但如果查看颜色属性,步幅相同,但偏移量为3个浮动-即:在位置数据之后).

让雷·温德里希澄清一下他的教程,这不是更有成效吗?此外,发布
glvertexattribbointer
调用会很好,这会阻止您跟随链接阅读教程。