diff --git a/examples/debug/main.cpp b/examples/debug/main.cpp index b282035..9bedc0f 100644 --- a/examples/debug/main.cpp +++ b/examples/debug/main.cpp @@ -66,6 +66,10 @@ int main(int argc, char** argv) // Make a square oglu::Object square(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology)); + oglu::Object square2(square); + + square.Move(-0.6f, 0.0f, 0.0f); + square2.Move(0.6f, 0.0f, 0.0f); // Create a shader oglu::Shader shader; @@ -97,16 +101,20 @@ int main(int argc, char** argv) oglu::ClearScreen(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, oglu::Color(0.29f, 0.13f, 0.23f)); square.Rotate(6.0f, 0.0f, 0.0f); + square2.Rotate(-6.0f, 0.0f, 0.0f); shader->Use(); shader->SetUniform("texture1", crate, 0); shader->SetUniform("texture2", opengl, 1); - shader->SetUniformMatrix4fv("model", 1, GL_FALSE, square.GetMatrix()); + shader->SetUniform("model", square); shader->SetUniformMatrix4fv("view", 1, GL_FALSE, glm::value_ptr(view)); shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(projection)); square.Render(); + shader->SetUniform("model", square2); + square2.Render(); + glfwSwapBuffers(window); glfwPollEvents(); } diff --git a/include/shader.hpp b/include/shader.hpp index f4ffd0b..91d13ab 100644 --- a/include/shader.hpp +++ b/include/shader.hpp @@ -15,6 +15,7 @@ namespace oglu { class Color; class AbstractTexture; + class Transformable; typedef std::shared_ptr Texture; @@ -305,10 +306,32 @@ namespace oglu * * @param[in] location Location of the uniform * @param[in] v0 Value to set the uniform to - * @param[in] ignoreAlpha Index of the texture unit + * @param[in] index Index of the texture unit */ void SetUniform(GLint location, const Texture& v0, GLbyte index = 0); + /** + * @brief Set uniform mat4. + * + * Sets the specified uniform to the transformation matrix of a + * Transformable object + * + * @param[in] name Name of the uniform + * @param[in] v0 Value to set the uniform to + */ + void SetUniform(const GLchar* name, Transformable& v0, GLboolean transpose = GL_FALSE); + + /** + * @brief Set uniform mat4. + * + * Sets the specified uniform to the transformation matrix of a + * Transformable object + * + * @param[in] location Location of the uniform + * @param[in] v0 Value to set the uniform to + */ + void SetUniform(GLint location, Transformable& v0, GLboolean transpose = GL_FALSE); + /** * @brief Set array of uniform float. * diff --git a/src/shader.cpp b/src/shader.cpp index 9e3e6d3..82211ab 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -7,6 +7,7 @@ #include #include +#include namespace oglu { @@ -247,6 +248,16 @@ namespace oglu glUniform1i(location, index); } + void AbstractShader::SetUniform(const GLchar* name, Transformable& v0, GLboolean transpose) + { + SetUniform(glGetUniformLocation(program, name), v0); + } + + void AbstractShader::SetUniform(GLint location, Transformable& v0, GLboolean transpose) + { + glUniformMatrix4fv(location, 1, transpose, v0.GetMatrix()); + } + void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value) { glUniform1fv(glGetUniformLocation(program, name), count, value);