Shaders can now handle objects
This commit is contained in:
parent
107e207a83
commit
7d3213166b
|
@ -66,6 +66,10 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
// Make a square
|
// Make a square
|
||||||
oglu::Object square(vertices, sizeof(vertices), indices, sizeof(indices), topology, sizeof(topology));
|
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
|
// Create a shader
|
||||||
oglu::Shader 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));
|
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);
|
square.Rotate(6.0f, 0.0f, 0.0f);
|
||||||
|
square2.Rotate(-6.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
shader->Use();
|
shader->Use();
|
||||||
shader->SetUniform("texture1", crate, 0);
|
shader->SetUniform("texture1", crate, 0);
|
||||||
shader->SetUniform("texture2", opengl, 1);
|
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("view", 1, GL_FALSE, glm::value_ptr(view));
|
||||||
shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(projection));
|
shader->SetUniformMatrix4fv("projection", 1, GL_FALSE, glm::value_ptr(projection));
|
||||||
|
|
||||||
square.Render();
|
square.Render();
|
||||||
|
|
||||||
|
shader->SetUniform("model", square2);
|
||||||
|
square2.Render();
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace oglu
|
||||||
{
|
{
|
||||||
class Color;
|
class Color;
|
||||||
class AbstractTexture;
|
class AbstractTexture;
|
||||||
|
class Transformable;
|
||||||
|
|
||||||
typedef std::shared_ptr<AbstractTexture> Texture;
|
typedef std::shared_ptr<AbstractTexture> Texture;
|
||||||
|
|
||||||
|
@ -305,10 +306,32 @@ namespace oglu
|
||||||
*
|
*
|
||||||
* @param[in] location Location of the uniform
|
* @param[in] location Location of the uniform
|
||||||
* @param[in] v0 Value to set the uniform to
|
* @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);
|
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.
|
* @brief Set array of uniform float.
|
||||||
*
|
*
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include <color.hpp>
|
#include <color.hpp>
|
||||||
#include <texture.hpp>
|
#include <texture.hpp>
|
||||||
|
#include <transformable.hpp>
|
||||||
|
|
||||||
namespace oglu
|
namespace oglu
|
||||||
{
|
{
|
||||||
|
@ -247,6 +248,16 @@ namespace oglu
|
||||||
glUniform1i(location, index);
|
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)
|
void AbstractShader::SetUniform1fv(const GLchar* name, GLsizei count, const GLfloat* value)
|
||||||
{
|
{
|
||||||
glUniform1fv(glGetUniformLocation(program, name), count, value);
|
glUniform1fv(glGetUniformLocation(program, name), count, value);
|
||||||
|
|
Loading…
Reference in a new issue