Текстурирование каждого многоугольника в массиве вершин - OpenGL

Я пытаюсь заставить мою функцию рендеринга работать. Я использую массивы вершин. Вот моя структура вершин.

struct Vertex 
{
    float x, y, z;              // The x, y and z floating point values     
    float u, v;                 // The u - v texture coordinates
    float padding[3];   // needs to be multiple of 32
};

Вот мой код рендеринга:

// Render the mesh
void WLD::render(GLuint* textures, long curRegion, CFrustum cfrustum)
{

    int num = 0;

    // Set up my indices
    GLuint indicies[3];

    // Cycle through the PVS
    while(num < regions[curRegion].visibility.size())
    {
        int i = regions[curRegion].visibility[num];

        if(!regions[i].dead && regions[i].meshptr != NULL)
        {
            if(cfrustum.BoxInFrustum(regions[i].meshptr->min[0], regions[i].meshptr->min[2], regions[i].meshptr->min[1], regions[i].meshptr->max[0], regions[i].meshptr->max[2], regions[i].meshptr->max[1]))
            {
                // Cycle through every polygon in the mesh and render it
                for(int j = 0; j < regions[i].meshptr->polygonCount; j++)
                {   
                    // Assign the index for the polygon to the index in the huge vertex array
                    indicies[0] = regions[i].meshptr->poly[j].vertIndex[0];
                    indicies[1] = regions[i].meshptr->poly[j].vertIndex[1];
                    indicies[2] = regions[i].meshptr->poly[j].vertIndex[2];

                    glEnableClientState(GL_VERTEX_ARRAY);
                    glVertexPointer(3, GL_FLOAT, sizeof(Vertex), &verticies[0].x);

                    // Texture index
                    int tex = regions[i].meshptr->poly[j].tex;
                    // Need to bind this to the polygon I render.

                    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
                    glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &verticies[0].u);
                    glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, indicies);

                    glDisableClientState(GL_VERTEX_ARRAY);
                    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
                }
            }
        }
    num++;
    }
}

Один из аргументов, GLuint * textures содержит все загруженные текстуры. Итак, значение, возвращаемое строкой int tex = region [i] .meshptr-> poly [j] .tex; - это индекс текстуры для этого конкретного многоугольника. Как мне привязать это к каждому многоугольнику при рендеринге? Дайте мне знать, если у вас есть какие-либо вопросы.

Я знаю, что мне нужно использовать glClientActiveTexture (), но во-первых, он говорит, что он не определен, и я не могу найти правильный заголовок, и, во-вторых, я не знаю, как он используется. Я не нашел хороших примеров. Итак, как мне, если, скажем, полигон ссылается на индекс текстуры 4, привязать его к многоугольнику, когда я визуализирую с помощью glClientActiveTexture.

5
задан genpfault 8 August 2011 в 13:06
поделиться