|
@@ -0,0 +1,123 @@
|
|
|
+#include "Cube.h"
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+using namespace glm;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+Cube::Cube(float taille, std::string const vertexShader, std::string const fragmentShader) : m_shader(vertexShader, fragmentShader)
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ m_shader.charger();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ taille /= 2;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ float verticesTmp[] = {-taille, -taille, -taille, taille, -taille, -taille, taille, taille, -taille,
|
|
|
+ -taille, -taille, -taille, -taille, taille, -taille, taille, taille, -taille,
|
|
|
+
|
|
|
+ taille, -taille, taille, taille, -taille, -taille, taille, taille, -taille,
|
|
|
+ taille, -taille, taille, taille, taille, taille, taille, taille, -taille,
|
|
|
+
|
|
|
+ -taille, -taille, taille, taille, -taille, taille, taille, -taille, -taille,
|
|
|
+ -taille, -taille, taille, -taille, -taille, -taille, taille, -taille, -taille,
|
|
|
+
|
|
|
+ -taille, -taille, taille, taille, -taille, taille, taille, taille, taille,
|
|
|
+ -taille, -taille, taille, -taille, taille, taille, taille, taille, taille,
|
|
|
+
|
|
|
+ -taille, -taille, -taille, -taille, -taille, taille, -taille, taille, taille,
|
|
|
+ -taille, -taille, -taille, -taille, taille, -taille, -taille, taille, taille,
|
|
|
+
|
|
|
+ -taille, taille, taille, taille, taille, taille, taille, taille, -taille,
|
|
|
+ -taille, taille, taille, -taille, taille, -taille, taille, taille, -taille};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ float couleursTmp[] = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
|
|
+ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
|
|
+
|
|
|
+ 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
|
|
|
+ 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
|
|
|
+
|
|
|
+ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
|
|
|
+ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
|
|
|
+
|
|
|
+ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
|
|
+ 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0,
|
|
|
+
|
|
|
+ 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
|
|
|
+ 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0,
|
|
|
+
|
|
|
+ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
|
|
|
+ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for(int i(0); i < 108; i++)
|
|
|
+ {
|
|
|
+ m_vertices[i] = verticesTmp[i];
|
|
|
+ m_couleurs[i] = couleursTmp[i];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+Cube::~Cube()
|
|
|
+{
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+void Cube::afficher(glm::mat4 &projection, glm::mat4 &modelview)
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ glUseProgram(m_shader.getProgramID());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, m_vertices);
|
|
|
+ glEnableVertexAttribArray(0);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, m_couleurs);
|
|
|
+ glEnableVertexAttribArray(1);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "projection"), 1, GL_FALSE, value_ptr(projection));
|
|
|
+ glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "modelview"), 1, GL_FALSE, value_ptr(modelview));
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ glDrawArrays(GL_TRIANGLES, 0, 36);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ glDisableVertexAttribArray(1);
|
|
|
+ glDisableVertexAttribArray(0);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ glUseProgram(0);
|
|
|
+}
|
|
|
+
|