123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- #include "Sol.h"
- using namespace glm;
- Sol::Sol(float longueur, float largeur, int repetitionLongueur, int repetitionLargeur, 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();
-
- longueur /= 2.0;
- largeur /= 2.0;
-
- float verticesTmp[] = {-longueur, 0, -largeur, longueur, 0, -largeur, longueur, 0, largeur,
- -longueur, 0, -largeur, -longueur, 0, largeur, longueur, 0, largeur};
-
- float coordTexture[] = {0, 0, repetitionLongueur, 0, repetitionLongueur, repetitionLargeur,
- 0, 0, 0, repetitionLargeur, repetitionLongueur, repetitionLargeur};
-
- for(int i(0); i < 18; i++)
- m_vertices[i] = verticesTmp[i];
-
- for(int i(0); i < 12; i++)
- m_coordTexture[i] = coordTexture[i];
- }
- Sol::~Sol()
- {
- }
- void Sol::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, 6);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glDisableVertexAttribArray(2);
- glDisableVertexAttribArray(0);
-
- glUseProgram(0);
- }
|