Um Texturen auf Objekten auszurichten benötigen wir Texturkoordinaten.

vertex.h

union Vertex {
    struct {
        Vector3 pos;
        Vector2 texcoord;
    };
    float values[5];
};

cgmath.h

union Vector2 {
    struct {
        float x, y;
    };
    float values[2];
};

mesh.cpp

void Mesh::init(Vertex* vertices, int vc)
{
    vertexCount = vc;
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);

    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);

    glBufferData(GL_ARRAY_BUFFER, vertexCount * sizeof(Vertex), vertices, GL_STATIC_DRAW);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)0);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)(3* sizeof(float)));
    glEnableVertexAttribArray(1);
}