OpenGL ES 索引问题

发布于 2025-01-07 00:29:57 字数 51 浏览 3 评论 0原文

我是 OpenGL ES 新手,我需要知道我们如何使用索引,因为我不明白我们使用的数字?

I am new to OpenGL ES and I need to know how we use the indices in that I didn't understand the numbers we used?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁微风不噪 2025-01-14 00:29:57

嗯,索引用于描述顶点的绘制顺序。
当您必须绘制一个由许多顶点组成但其中许多是相同点的对象时,这非常有用。

因此,例如,当你想用 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

Well ,the indices are used to describe in what order the vertices should be drawn.
This is usefull when you have to draw an object which is consisted by many vertices but many of them are the same points.

So for example when you want to draw a square with glDrawElements(with indices) you have

//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

In the other hand if you want to draw a square with glDrawArrays(without indices) you have

 //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
风渺 2025-01-14 00:29:57

本文
这可能会帮助您了解指数。在代码中我们使用这个结构:

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

This article
this may help you get an idea about indices. In code we use this structure:

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    
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文