Commit 06f1c5a3 authored by Sadman Kazi's avatar Sadman Kazi 🎸

Add uniform to shader

parent 0c53745b
Pipeline #87 passed with stage
in 2 minutes and 33 seconds
......@@ -4,6 +4,8 @@ layout (location = 0) in vec3 position;
out vec4 color;
uniform mat4 u_transform;
void main () {
color = vec4(clamp(position, 0.0, 1.0), 1.0);
gl_Position = vec4(1.5*position, 1.0);
......
......@@ -57,4 +57,4 @@ private:
glm::vec3 m_up;
};
#endif CAMERA_H_INCLUDED
\ No newline at end of file
#endif //CAMERA_H_INCLUDED
......@@ -40,7 +40,7 @@ Game::Game()
m_transform->setScale(glm::vec3(0.5f, 0.5f, 0.5f));
m_shader->addUniform("transform");
m_shader->addUniform("u_transform");
m_counter = 0;
}
......@@ -84,8 +84,8 @@ void Game::update() {
float absSinCounter = abs(sinCounter);
//transform->GetPos().x = sinCounter;
m_transform->getRot().y = sinCounter;
//m_transform->getRot().y = sinCounter;
//transform->GetRot().z = sinCounter;
m_shader->setUniformMat4("transform", m_transform->getProjectedModel(m_camera));
m_shader->setUniformMat4("u_transform", m_transform->getProjectedModel(m_camera));
}
......@@ -40,10 +40,11 @@ void Shader::addUniform(const std::string& uniform) {
if (uniformLocation < 0) {
std::cerr << "Error: Could not find uniform " << uniform << std::endl;
}
//once we know that the uniform exists, add it to the hash map
uniforms.insert({ uniform, uniformLocation });
throw std::exception(); // TODO: Custom exception class
} else {
//once we know that the uniform exists, add it to the hash map
uniforms.insert({ uniform, uniformLocation });
}
}
void Shader::setUniformI(const std::string& name, int value) {
......@@ -128,4 +129,4 @@ static void checkError(GLuint shader, GLuint flag, bool isProgram, const std::st
std::cerr << errorMessage << ": '" << error << "'" << std::endl;
}
}
\ No newline at end of file
}
......@@ -47,4 +47,4 @@ public:
private:
glm::vec3 m_pos, m_rot, m_scale; //m_ refers to member variables
};
#endif CAMERA_H_INCLUDED
\ No newline at end of file
#endif // TRANSFORM_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment