Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Ex8::draw(){
- GLfloat t = glfwGetTime();
- glm::mat4 model;
- model = glm::rotate(model, t, glm::vec3(0.f, 1.f, 0.f));
- model = glm::scale(model, glm::vec3(0.5f, 0.5f, 0.5f));
- glm::mat4 view = glm::lookAt( _eye, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f));
- glm::mat4 transform;
- glm::mat4 lModel;
- lModel = glm::rotate(lModel, -t, glm::vec3(1.f, 1.f, 1.f));
- lModel = glm::translate(lModel, glm::vec3(0.7f, 0.f, 0.f));
- lModel = glm::scale(lModel, glm::vec3(0.1f, 0.1f, 0.1f));
- transform = _projection * view * lModel;
- _light.pos = utils::m4_v3(lModel);
- _shaderO.bind();
- GLuint id = _shaderO.getID();
- glUniformMatrix4fv(glGetUniformLocation(id, "model"), 1, GL_FALSE, glm::value_ptr(model));
- glUniformMatrix4fv(glGetUniformLocation(id, "view"), 1, GL_FALSE, glm::value_ptr(view));
- glUniformMatrix4fv(glGetUniformLocation(id, "projection"), 1, GL_FALSE, glm::value_ptr(_projection));
- glUniform3fv(glGetUniformLocation(id, "eyePos"), 1, glm::value_ptr(eye));
- GLint ambLoc = glGetUniformLocation(id, "material.ambient");
- GLint difLoc = glGetUniformLocation(id, "material.diffuse");
- GLint spcLoc = glGetUniformLocation(id, "material.specular");
- GLint shnLoc = glGetUniformLocation(id, "material.shininess");
- _material.bindTo(_shaderO);
- _light.bindTo(_shaderO);
- glBindVertexArray(_vaoObj);
- glDrawArrays(GL_TRIANGLES, 0, 36);
- glBindVertexArray(NULL);
- _shaderO.unbind();
- _shaderL.bind();
- glUniformMatrix4fv(glGetUniformLocation(_shaderL.getID(), "transform"), 1, GL_FALSE, glm::value_ptr(transform));
- glBindVertexArray(_vaoObj);
- glDrawArrays(GL_TRIANGLES, 0, 36);
- glBindVertexArray(NULL);
- _shaderL.unbind();
- }
- void Material_8::bindTo(const ShaderProg & shader) {
- if (!diffuse || !specular) return;
- GLuint id = shader.getID();
- GLint ambLoc = glGetUniformLocation(id, "material.ambient");
- GLint difLoc = glGetUniformLocation(id, "material.diffuse");
- GLint spcLoc = glGetUniformLocation(id, "material.specular");
- GLint shnLoc = glGetUniformLocation(id, "material.shininess");
- glUniform3fv(ambLoc, 1, glm::value_ptr(ambient));
- glUniform1f(shnLoc, shininess);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, diffuse->getID());
- glUniform1i(difLoc, GL_TEXTURE0);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, specular->getID());
- glUniform1i(spcLoc, GL_TEXTURE1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement