summary refs log tree commit diff
path: root/src/Shader
diff options
context:
space:
mode:
Diffstat (limited to 'src/Shader')
-rw-r--r--src/Shader/ShaderProgram.cpp10
-rw-r--r--src/Shader/ShaderProgram.hpp10
-rw-r--r--src/Shader/Uniform.cpp14
-rw-r--r--src/Shader/Uniform.hpp23
-rw-r--r--src/Shader/fragment.glsl5
-rw-r--r--src/Shader/vertex.glsl6
6 files changed, 62 insertions, 6 deletions
diff --git a/src/Shader/ShaderProgram.cpp b/src/Shader/ShaderProgram.cpp
index 854b1bf..4d0b684 100644
--- a/src/Shader/ShaderProgram.cpp
+++ b/src/Shader/ShaderProgram.cpp
@@ -29,4 +29,14 @@ void ShaderProgram::bind() const {
     glUseProgram(m_program);
 }
 
+Uniform ShaderProgram::uniform(const std::string& name) const {
+    auto index = glGetUniformLocation(m_program, name.c_str());
+
+    return {name, static_cast<uint32_t>(index)};
+}
+
+uint32_t ShaderProgram::get() const {
+    return m_program;
+}
+
 }
diff --git a/src/Shader/ShaderProgram.hpp b/src/Shader/ShaderProgram.hpp
index 800e3ff..857dc2f 100644
--- a/src/Shader/ShaderProgram.hpp
+++ b/src/Shader/ShaderProgram.hpp
@@ -1,6 +1,10 @@
 #pragma once
 
+#include <string>
+#include <vector>
 #include "Shader.hpp"
+#include "../Math/Math.hpp"
+#include "Uniform.hpp"
 
 namespace MC {
 
@@ -8,9 +12,11 @@ class ShaderProgram {
 public:
     ShaderProgram(Shader fragment, Shader vertex);
 
-    void bind() const;
+    uint32_t get() const;
+
+    Uniform uniform(const std::string& name) const;
 
-    uint32_t get();
+    void bind() const;
 
 private:
     uint32_t m_program;
diff --git a/src/Shader/Uniform.cpp b/src/Shader/Uniform.cpp
new file mode 100644
index 0000000..71b7633
--- /dev/null
+++ b/src/Shader/Uniform.cpp
@@ -0,0 +1,14 @@
+#include <GL/glew.h>
+#include "Uniform.hpp"
+
+namespace MC {
+
+void Uniform::set(Matrix<4, 4> value) const {
+    glUniformMatrix4fv(m_index, 1, GL_TRUE, value.elements);
+}
+
+void Uniform::set(Vector<3> value) const {
+    glUniform3f(m_index, value.x(), value.y(), value.z());
+}
+
+}
diff --git a/src/Shader/Uniform.hpp b/src/Shader/Uniform.hpp
new file mode 100644
index 0000000..58cdc28
--- /dev/null
+++ b/src/Shader/Uniform.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <cstdint>
+#include <string>
+#include <utility>
+#include "../Math/Math.hpp"
+
+namespace MC {
+
+class Uniform {
+public:
+    Uniform(std::string name, uint32_t index)
+        : m_name(std::move(name)), m_index(index) {};
+
+    void set(Matrix<4, 4> value) const;
+    void set(Vector<3> value) const;
+
+private:
+    std::string m_name;
+    uint32_t m_index;
+};
+
+}
diff --git a/src/Shader/fragment.glsl b/src/Shader/fragment.glsl
index 017a2c8..ba5ed93 100644
--- a/src/Shader/fragment.glsl
+++ b/src/Shader/fragment.glsl
@@ -2,7 +2,6 @@
 
 out vec4 color;
 
-void main()
-{
-    color = vec4(1.0f, 0.5f, 0.2f, 1.0f);
+void main() {
+    color = vec4(0.2f, 0.6f, 0.6f, 1.0f); // #339999
 }
\ No newline at end of file
diff --git a/src/Shader/vertex.glsl b/src/Shader/vertex.glsl
index 8b1bbbd..e7b9e3d 100644
--- a/src/Shader/vertex.glsl
+++ b/src/Shader/vertex.glsl
@@ -1,7 +1,11 @@
 #version 330 core
 
+uniform mat4 model_matrix;
+uniform mat4 view_matrix;
+uniform mat4 projection_matrix;
+
 in vec3 position;
 
 void main() {
-    gl_Position = vec4(position.x, position.y, position.z, 1.0);
+    gl_Position = projection_matrix * view_matrix * model_matrix * vec4(position, 1.0);
 }
\ No newline at end of file