glVertexAttribPointer

草稿:


float positions[6] = {
-0.5f, -0.5f,
0.0f, 0.5f,
0.5f, -0.5f,
};

unsigned int buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(float), positions, GL_STATIC_DRAW);

glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0);


attribute: position, UV, color 之类的
vertex: 一组 attribute


glVertexAttribPointer:
0,
2 -> 2个参数
GL_FLOAT, type为float
GL_FALSE, 转为float, 如果是int,转为-1,1, byte: 0, 255
sizeof(float) * 2, 一组 vertex的大小,
0, pointer->是指要获取数据的偏移。 attribute的偏移。例如 vertex的内容为: color, position, UV. 这个时候如果想获取position, 则需要跳过 color的大小。

猜你喜欢

转载自www.cnblogs.com/weishuan/p/12927198.html