1

我正在制作一个天空盒(在它的 6 个面上每个面都有不同纹理的立方体),这就是我所做的:

我定义我的顶点:

const float vertices[8u][3u] = {
    {-1.0f, -1.0f, -1.0f},
    {-1.0f, -1.0f, 1.0f},
    {-1.0f, 1.0f, -1.0f},
    {-1.0f, 1.0f, 1.0f},
    {1.0f, -1.0f, -1.0f},
    {1.0f, -1.0f, 1.0f},
    {1.0f, 1.0f, -1.0f},
    {1.0f, 1.0f, 1.0f}
};

我根据 vertices 数组定义了我的三角形(四边形在 ES 版本中不可用):

const unsigned short elements[8u][3u] = {
    {4u, 6u, 2u},
    {4u, 0u, 2u},
    {6u, 3u, 2u},
    {6u, 3u, 7u},
    {7u, 1u, 5u},
    {7u, 1u, 3u},
    {5u, 0u, 4u},
    {5u, 0u, 1u}
};

据我了解,我现在需要定义我的纹理坐标,我尝试了很多不同的东西,现在看起来像这样:

float texCoords[4u][2u] = {
    {0.0f, 0.0f},
    {1.0f, 0.0f},
    {1.0f, 1.0f},
    {0.0f, 1.0f}
};

编辑:天空盒绝对不会显示自己,我只看到一个 2d 平面图像,其中我的纹理以一种奇怪的方式重复。绝对没有立方体

绘图部分正在工作,我认为我的问题是基于纹理坐标,对吗?我做错了什么?

4

2 回答 2

0

我对吗 ?我做错了什么?

凝视着我的水晶球……不,我不明白你的问题是什么,你也没有告诉我们。

无论如何,你的纹理坐标确实是错误的,你的数组只包含 4 个。但是你有一个 8 个顶点的立方体。然而,要让它成为一个天空盒,您需要一个 24 个顶点的立方体,因为纹理坐标是顶点的一部分,对于由 6 个纹理组成的天空盒,您不能在某些顶点上共享纹理坐标。

但是,我建议您改用立方体贴图纹理,这有很大的好处,您可以使用顶点坐标,因为您已经拥有它们,也可以用于纹理坐标。

于 2012-09-19T12:48:12.063 回答
-1

抱歉,我的问题不清楚。我真的不明白纹理坐标的概念是什么。现在我想我做到了:告诉你希望每张脸都被你的纹理填满多少。我的例子是完全填充。这是我的新(看起来像)工作代码,以防它可以帮助某人:

//The 24 vertex of the 3d cube (the skybox)
static const float vertices[24u][3u] = {
        {-1.0f, -1.0f, -1.0f}, //face 1 (front)
        {-1.0f, 1.0f, -1.0f},
        {1.0f, -1.0f, -1.0f},
        {1.0f, 1.0f, -1.0f},

        {1.0f, 1.0f, 1.0f}, //face 2 (back)
        {1.0f, -1.0f, 1.0f},
        {-1.0f, 1.0f, 1.0f},
        {-1.0f, -1.0f, 1.0f},

        {-1.0f, -1.0f, -1.0f}, //face 3 (left)
        {-1.0f, -1.0f, 1.0f},
        {-1.0f, 1.0f, -1.0f},
        {-1.0f, 1.0f, 1.0f}, 

        {1.0f, 1.0f, 1.0f}, //face 4 (right)
        {1.0f, 1.0f, -1.0f},
        {1.0f, -1.0f, 1.0f},
        {1.0f, -1.0f, -1.0f},

        {-1.0f, 1.0f, -1.0f}, // face 5 (up)
        {-1.0f, 1.0f, 1.0f},
        {1.0f, 1.0f, 1.0f},
        {1.0f, 1.0f, -1.0f},

        {1.0f, -1.0f, 1.0f}, //face 6 (bot)
        {1.0f, -1.0f, -1.0f},
        {-1.0f, -1.0f, -1.0f},
        {-1.0f, -1.0f, 1.0f},
};

//Coordinate of the textures
float texCoords[24u][2u] = {
        {0.0f, 0.0f},
        {0.0f, 1.0f},
        {1.0f, 1.0f},
        {1.0f, 0.0f},

        {0.0f, 0.0f},
        {0.0f, 1.0f},
        {1.0f, 1.0f},
        {1.0f, 0.0f},

        {0.0f, 0.0f},
        {0.0f, 1.0f},
        {1.0f, 1.0f},
        {1.0f, 0.0f},

        {0.0f, 0.0f},
        {0.0f, 1.0f},
        {1.0f, 1.0f},
        {1.0f, 0.0f},

        {0.0f, 0.0f},
        {0.0f, 1.0f},
        {1.0f, 1.0f},
        {1.0f, 0.0f},

        {0.0f, 0.0f},
        {0.0f, 1.0f},
        {1.0f, 1.0f},
        {1.0f, 0.0f},        
};

//Defining triangles based on the vertice array indexes
const unsigned short elements[12u][3u] = {
        {0, 2, 1},
        {2, 1, 3},

        {4, 5, 6},
        {5, 6, 7},

        {8, 9, 10},
        {9, 10, 11},

        {12, 13, 14},
        {13, 14, 15},

        {16, 17, 18},
        {17, 18, 19},

        {20, 21, 22},
        {21, 22, 23}
};
于 2012-09-20T07:42:48.417 回答