2012-02-18 59 views

回答

2

那么,索引用来描述顶点应该按什么顺序绘制。 当你必须绘制一个由许多顶点组成的对象时,这是有用的,但其中许多顶点是相同的点。

因此,例如,当你想绘制glDrawElements方(含索引)你有

//vertices 
-1,-1,0, //0 bottom left 
-1,1,0, //1 top left 
1,1,0, //2 top right 
1,-1,0 //3 bottom right 

//indices 
0   //0 bottom left 
1   //1 top left 
2   //2 top right 
2   //2 top right 
3   //3 bottom right 
0   //0 bottom left 

在另一方面,如果你想绘制调用glDrawArrays方(没有索引)你有

//vertices 
-1,-1,0, //0 bottom left 
-1,1,0, //1 top left 
1,1,0, //2 top right 
1,1,0, //2 top right 
1,-1,0 //3 bottom right 
-1,-1,0, //0 bottom left 
-1

This article 这可能会帮助您了解指数。在代码中,我们使用这种结构:

const Vertex Vertices[] = { 
    {{1, -1, 0}, {1, 0, 0, 1}},//0 
    {{1, 1, 0}, {1, 0, 0, 1}},//1 
    {{-1, 1, 0}, {0, 1, 0, 1}},//2 
    {{-1, -1, 0}, {0, 1, 0, 1}},//3 
    {{1, -1, -1}, {1, 0, 0, 1}},//4 
    {{1, 1, -1}, {1, 0, 0, 1}},//5 
    {{-1, 1, -1}, {0, 1, 0, 1}},//6 
    {{-1, -1, -1}, {0, 1, 0, 1}}//7 
}; 

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  
}; 
+1

所以你已经发布了很多顶点和索引。实际解释他们是什么以及他们做什么?链接没问题,但您可能希望至少总结这里的内容,因此答案是独立的。 – Bart 2012-02-18 09:37:28

+0

雅,我会解释他,如果他要求 – 2012-02-18 09:42:38

+0

在评论中我提到他的数字。 – 2012-02-18 09:43:36