具有多个属性的顶点缓冲区上的索引缓冲区-OpenGL

时间:2019-06-08 15:04:06

标签: c opengl

上下文:

  • OpenGl C API> = 4.1

问题:

这是一个 VBO (顶点缓冲区),其中每个顶点由位置(3 GLfloat颜色(3 { {1}})

这是 VBO 的内存表示形式。

在以下表示中, p1 代表顶点1的位置 c1 代表顶点1的颜色。 >, p2 代表顶点2的位置 c2 代表顶点2的颜色,等等。

GLfloat

VBO 已绑定到 VAO 。位置和颜色属性声明如下:

VBO: [p1_x, p1_y, p1_z, c1_x, c1_y, c1_z, p2_x, p2_y, p2_z, c2_x, c2_y, c2_z, ...]
      |                                   |
      |                                   |
      |                                   |
      start of vertex 1                    start of vertex 2

现在可以将索引缓冲区IBO 与该 VBO 一起使用,以便每个索引都指向每个顶点的起点吗?

在单个 VBO 中使用多个属性是否允许以这种方式建立索引?

// Enable two attributes position and color

// Enable position attribute
id_position = glGetAttribLocation(id_program, "position");
glEnableVertexAttribArray(id_position);
glVertexAttribPointer(id_position ,
        3,
        GL_FLOAT,
        GL_FALSE,
        sizeof(GLfloat) * 3 + sizeof(GLfloat) * 3,
        (uint8_t *)NULL);

// Enable color attribute
id_color = glGetAttribLocation(id_program, "color");
glVertexAttribPointer(id_color);
glVertexAttribPointer(id_color ,
        3,
        GL_FLOAT,
        GL_FALSE,
        sizeof(GLfloat) * 3 + sizeof(GLfloat) * 3,
        (uint8_t *)NULL + (sizeof(t_vec3)));

我发现 IBO 的示例仅包含具有单个位置成分here的顶点。

This link似乎是一个相关问题,但我很难理解。

0 个答案:

没有答案