1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
void dessinerObjet(GLenum mode, float vertexTab[], int vertexTabSize, float colorTab[], int colorTabSize, GLuint shaderId, mat4 * modelMatrix, mat4 * viewMatrix, mat4 * projectionMatrix) {
//Vbo vertex
GLuint idVertexVbo;
glGenBuffers(1, &idVertexVbo);
glBindBuffer(GL_ARRAY_BUFFER, idVertexVbo);
glBufferData(GL_ARRAY_BUFFER, vertexTabSize * sizeof(float), vertexTab, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
//Vbo color
GLuint idColorVbo;
glGenBuffers(1, &idColorVbo);
glBindBuffer(GL_ARRAY_BUFFER, idColorVbo);
glBufferData(GL_ARRAY_BUFFER, colorTabSize * sizeof(float), colorTab, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Programmation Vao
GLuint idVao;
glGenVertexArrays(1, &idVao);
glBindVertexArray(idVao);
// pointeur tableau vertex
glBindBuffer(GL_ARRAY_BUFFER, idVertexVbo);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// pointeur tableau couleur
glBindBuffer(GL_ARRAY_BUFFER, idColorVbo);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
// Localisation des variables uniformes du shader
GLuint idModelMatrix = glGetUniformLocation(shaderId, "modelMatrix");
GLuint idViewMatrix = glGetUniformLocation(shaderId, "viewMatrix");
GLuint idProjectionMatrix = glGetUniformLocation(shaderId, "projectionMatrix");
// Envoi des matrices aux variables uniformes du shader
glUniformMatrix4fv(idModelMatrix, 1, GL_FALSE, &(*modelMatrix)[0][0]);
glUniformMatrix4fv(idViewMatrix, 1, GL_FALSE, &(*viewMatrix)[0][0]);
glUniformMatrix4fv(idProjectionMatrix, 1, GL_FALSE, &(*projectionMatrix)[0][0]);
// Execution Vao
glBindVertexArray(idVao);
glUseProgram(shaderId);
glDrawArrays(mode, 0, 6);
glBindVertexArray(0);
// Suppresion Vao et Vbo
glDisableVertexAttribArray(0);
glDeleteVertexArrays(1, &idVao);
glDeleteBuffers(1, &idVertexVbo);
glDeleteBuffers(1, &idColorVbo);
//glDeleteProgram(idShader);
} |
Partager