123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- #include "Caisse.h"
- using namespace glm;
- Caisse::Caisse(float taille, std::string const texture) : Cube(taille),
- m_texture(texture),
- m_tailleCoordTextureBytes(72 * sizeof(float))
- {
-
- float coordTextureTmp[] = {0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1,
- 0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1,
- 0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1,
- 0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1,
- 0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1,
- 0, 0, 1, 0, 1, 1,
- 0, 0, 0, 1, 1, 1};
-
- for(int i (0); i < 72; i++)
- m_coordTexture[i] = coordTextureTmp[i];
-
- charger();
- }
- Caisse::~Caisse()
- {
- }
- void Caisse::charger()
- {
-
- if(glIsBuffer(m_vboID) == GL_TRUE)
- glDeleteBuffers(1, &m_vboID);
-
- glGenBuffers(1, &m_vboID);
-
- glBindBuffer(GL_ARRAY_BUFFER, m_vboID);
-
- glBufferData(GL_ARRAY_BUFFER, m_tailleVerticesBytes + m_tailleCoordTextureBytes, 0, GL_STATIC_DRAW);
-
- glBufferSubData(GL_ARRAY_BUFFER, 0, m_tailleVerticesBytes, m_vertices);
- glBufferSubData(GL_ARRAY_BUFFER, m_tailleVerticesBytes, m_tailleCoordTextureBytes, m_coordTexture);
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- if(glIsVertexArray(m_vaoID) == GL_TRUE)
- glDeleteVertexArrays(1, &m_vaoID);
-
- glGenVertexArrays(1, &m_vaoID);
-
- glBindVertexArray(m_vaoID);
-
- glBindBuffer(GL_ARRAY_BUFFER, m_vboID);
-
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
- glEnableVertexAttribArray(0);
-
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(m_tailleVerticesBytes));
- glEnableVertexAttribArray(2);
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- glBindVertexArray(0);
- }
- void Caisse::afficher(glm::mat4 pmv, Shader const &shad)
- {
-
- glBindVertexArray(m_vaoID);
-
- glUniformMatrix4fv(glGetUniformLocation(shad.getProgramID(), "pmv"), 1, GL_FALSE, glm::value_ptr(pmv));
-
- glBindTexture(GL_TEXTURE_2D, m_texture.getID());
-
- glDrawArrays(GL_TRIANGLES, 0, 36);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glBindVertexArray(0);
- }
|