首先来看索引图对应的连接方式
在OpenGL中索引绘图区别普通绘制,其步骤是
先建立绘图索引数组其内容如:
GLuintindices[] =
{
0,3,2,
0,1,3,
0,2,4,
0,4,1,
2,3,4,
1,4,3,
};
//将顶点数组放入数组缓冲区中 GL_ARRAY_BUFFER
GLuintbuffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(attrArr), attrArr, GL_STATIC_DRAW);
//将索引数组存储到索引缓冲区 GL_ELEMENT_ARRAY_BUFFER
GLuintindex;
glGenBuffers(1, &index);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
使用索引绘图,优点是合理利用一些点的位置信息,根据索引对目标图片的绘制,对顶点坐标和纹理坐标的信息简化,便于修改