123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "Cristal.h"
- using namespace glm;
- Cristal::Cristal(std::string const vertexShader, std::string const fragmentShader, std::string const texture) : m_shader(vertexShader, fragmentShader), m_texture(texture)
- {
-
- m_shader.charger();
-
- m_texture.charger();
-
- float verticesTmp[] = {-0.5, 0, -0.5, 0.5, 0, -0.5, 0, 1, 0,
- 0.5, 0, -0.5, 0.5, 0, 0.5, 0, 1, 0,
- 0.5, 0, 0.5, -0.5, 0, 0.5, 0, 1, 0,
- -0.5, 0, 0.5, -0.5, 0, -0.5, 0, 1, 0,
- -0.5, 0, -0.5, 0.5, 0, -0.5, 0, -1, 0,
- 0.5, 0, -0.5, 0.5, 0, 0.5, 0, -1, 0,
- 0.5, 0, 0.5, -0.5, 0, 0.5, 0, -1, 0,
- -0.5, 0, 0.5, -0.5, 0, -0.5, 0, -1, 0};
-
- float coordTexture[] = {0, 0, 0.5, 0, 0.5, 0.5,
- 0, 0, 0.5, 0, 0.5, 0.5,
- 0, 0, 0.5, 0, 0.5, 0.5,
- 0, 0, 0.5, 0, 0.5, 0.5,
- 0, 0, 0.5, 0, 0.5, 0.5,
- 0, 0, 0.5, 0, 0.5, 0.5,
- 0, 0, 0.5, 0, 0.5, 0.5,
- 0, 0, 0.5, 0, 0.5, 0.5};
-
- for(int i(0); i < 72; i++)
- m_vertices[i] = verticesTmp[i];
-
- for(int i(0); i < 48; i++)
- m_coordTexture[i] = coordTexture[i];
- }
- void Cristal::afficher(glm::mat4 &projection, glm::mat4 &modelview)
- {
-
- glUseProgram(m_shader.getProgramID());
-
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, m_vertices);
- glEnableVertexAttribArray(0);
-
- glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, m_coordTexture);
- glEnableVertexAttribArray(2);
-
- glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "projection"), 1, GL_FALSE, value_ptr(projection));
- glUniformMatrix4fv(glGetUniformLocation(m_shader.getProgramID(), "modelview"), 1, GL_FALSE, value_ptr(modelview));
-
- glBindTexture(GL_TEXTURE_2D, m_texture.getID());
-
- glDrawArrays(GL_TRIANGLES, 0, 24);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glDisableVertexAttribArray(2);
- glDisableVertexAttribArray(0);
-
- glUseProgram(0);
- }
|