1
votes

I'm making a skybox (cube with different texture on each of its 6 faces) here's what I do :

I define my vertices :

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

I define my triangles (quads are not available in ES version) based on the vertices array :

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

As I understood I now need to define my texture coordinates, I tried many different things, for now it looks like this :

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

Edit: The skybox absolutely doesn't display itself, I only see a 2d flat image where my texture is repeated in a strange way. Absolutly no cube

The drawing part is working, I think my problem is based on the Texture coordinate, Am I right ? what did I've made wrong ?

2
And what exactly is your problem? You wrote that drawing works, but not, what doesn't work.datenwolf
I was meaning that the drawing function is supposed to be working. My problem is that the display is absolutly not a cube but a 2D flat image with my texture randomly repeated on itIggY
Well, without either a screenshot, or the source code of the display function I can do only worse than speculate. I need much more information from you, to give useful help.datenwolf

2 Answers

0
votes

Am I right ? what did I've made wrong?

Gazing into my crystal ball… Nope I don't see what your problem is, and you didn't tell us.

Anyway, your texture coordinates are indeed wrong, your array contains only 4. But you have a cube of 8 vertices. However for this to become a skybox, you need a cube of 24 vertices, because the texture coordinate is part of the vertex and you can not share texture coordinates on some of the vertices for a sky box made of 6 textures.

However I recommend you to use a cubemap texture instead, which has the big benefit, that you can use the vertex coordinates, as you already have them, also for texture coordinates.

-1
votes

Sorry my question wasn't clear. I didn't really understood what was the idea of Texture coordinates. Now I think I did : Telling how much you want each face to be fulled by your texture. My example is for full-filling. Here's my new (looking like) working code, in case it may help someone :

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