| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 | #include "Cube.h"// Permet d'éviter la ré-écriture du namespace glm::using namespace glm;// Constructeur et DestructeurCube::Cube(float taille, std::string const vertexShader, std::string const fragmentShader) : m_shader(vertexShader, fragmentShader){    // Chargement du shader    m_shader.charger();    // Division de la taille    taille /= 2;    // Vertices temporaires    float verticesTmp[] = {-taille, -taille, -taille,   taille, -taille, -taille,   taille, taille, -taille,     // Face 1                           -taille, -taille, -taille,   -taille, taille, -taille,   taille, taille, -taille,     // Face 1                           taille, -taille, taille,   taille, -taille, -taille,   taille, taille, -taille,       // Face 2                           taille, -taille, taille,   taille, taille, taille,   taille, taille, -taille,         // Face 2                           -taille, -taille, taille,   taille, -taille, taille,   taille, -taille, -taille,      // Face 3                           -taille, -taille, taille,   -taille, -taille, -taille,   taille, -taille, -taille,    // Face 3                           -taille, -taille, taille,   taille, -taille, taille,   taille, taille, taille,        // Face 4                           -taille, -taille, taille,   -taille, taille, taille,   taille, taille, taille,        // Face 4                           -taille, -taille, -taille,   -taille, -taille, taille,   -taille, taille, taille,     // Face 5                           -taille, -taille, -taille,   -taille, taille, -taille,   -taille, taille, taille,     // Face 5                           -taille, taille, taille,   taille, taille, taille,   taille, taille, -taille,         // Face 6                           -taille, taille, taille,   -taille, taille, -taille,   taille, taille, -taille};      // Face 6    // Couleurs temporaires    float couleursTmp[] = {1.0, 0.0, 0.0,   1.0, 0.0, 0.0,   1.0, 0.0, 0.0,           // Face 1                           1.0, 0.0, 0.0,   1.0, 0.0, 0.0,   1.0, 0.0, 0.0,           // Face 1                           0.0, 1.0, 0.0,   0.0, 1.0, 0.0,   0.0, 1.0, 0.0,           // Face 2                           0.0, 1.0, 0.0,   0.0, 1.0, 0.0,   0.0, 1.0, 0.0,           // Face 2                           0.0, 0.0, 1.0,   0.0, 0.0, 1.0,   0.0, 0.0, 1.0,           // Face 3                           0.0, 0.0, 1.0,   0.0, 0.0, 1.0,   0.0, 0.0, 1.0,           // Face 3                           1.0, 0.0, 0.0,   1.0, 0.0, 0.0,   1.0, 0.0, 0.0,           // Face 4                           1.0, 0.0, 0.0,   1.0, 0.0, 0.0,   1.0, 0.0, 0.0,           // Face 4                           0.0, 1.0, 0.0,   0.0, 1.0, 0.0,   0.0, 1.0, 0.0,           // Face 5                           0.0, 1.0, 0.0,   0.0, 1.0, 0.0,   0.0, 1.0, 0.0,           // Face 5                           0.0, 0.0, 1.0,   0.0, 0.0, 1.0,   0.0, 0.0, 1.0,           // Face 6                           0.0, 0.0, 1.0,   0.0, 0.0, 1.0,   0.0, 0.0, 1.0};          // Face 6    // Copie des valeurs dans les tableaux finaux    for(int i(0); i < 108; i++)    {        m_vertices[i] = verticesTmp[i];        m_couleurs[i] = couleursTmp[i];    }}Cube::~Cube(){}// Méthodesvoid Cube::afficher(glm::mat4 &projection, glm::mat4 &modelview){    // Activation du shader    glUseProgram(m_shader.getProgramID());        // Envoi des vertices        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, m_vertices);        glEnableVertexAttribArray(0);        // Envoi de la couleur        glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, m_couleurs);        glEnableVertexAttribArray(1);        // Envoi des matrices        glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "projection"), 1, GL_FALSE, value_ptr(projection));        glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "modelview"), 1, GL_FALSE, value_ptr(modelview));        // Rendu        glDrawArrays(GL_TRIANGLES, 0, 36);        // Désactivation des tableaux        glDisableVertexAttribArray(1);        glDisableVertexAttribArray(0);    // Désactivation du shader    glUseProgram(0);}
 |