diff --git a/src/ShaderProgram.hpp b/src/ShaderProgram.hpp index f604f1f..99418e4 100644 --- a/src/ShaderProgram.hpp +++ b/src/ShaderProgram.hpp @@ -77,6 +77,8 @@ public: glUseProgram(program_id); } + unsigned int vertexShader_id, fragmentShader_id, program_id; + private: void LoadFile(std::string path, char** source) { @@ -90,6 +92,4 @@ private: memcpy_s(*source, s, shader.c_str(), s); (*source)[s] = '\0'; } - - unsigned int vertexShader_id, fragmentShader_id, program_id; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index bec458a..8345dc7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -76,10 +76,14 @@ int main(int argc, char** argv) { glfwPollEvents(); + float time = glfwGetTime(); + int timeUniformLocation = glGetUniformLocation(program.program_id, "t"); + glClearColor(0.4f, 0.1f, 0.5f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); program.Use(); + glUniform1f(timeUniformLocation, time); q.Draw(); glfwSwapBuffers(window); diff --git a/src/primitives/Quad.hpp b/src/primitives/Quad.hpp index 0fd6683..bb96f1e 100644 --- a/src/primitives/Quad.hpp +++ b/src/primitives/Quad.hpp @@ -37,7 +37,6 @@ public: { glBindVertexArray(VAO); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices); - glBindVertexArray(0); } private: diff --git a/src/primitives/Triangle.hpp b/src/primitives/Triangle.hpp index 6f0fd71..c2d9aea 100644 --- a/src/primitives/Triangle.hpp +++ b/src/primitives/Triangle.hpp @@ -28,7 +28,6 @@ public: { glBindVertexArray(VAO); glDrawArrays(GL_TRIANGLES, 0, 3); - glBindVertexArray(0); } private: diff --git a/src/shaders/triangle.frag b/src/shaders/triangle.frag index c6bc8c8..f685067 100644 --- a/src/shaders/triangle.frag +++ b/src/shaders/triangle.frag @@ -1,8 +1,11 @@ #version 460 core out vec4 FragColor; +in vec4 vertexColor; + +uniform float t; void main() { - FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); + FragColor = vertexColor * vec4((sin(t) + 1.f) / 2, (cos(t) + 1.f) / 2, (-sin(t) + 1.f), 1.f); } \ No newline at end of file diff --git a/src/shaders/triangle.vert b/src/shaders/triangle.vert index e19ad4f..c3295e0 100644 --- a/src/shaders/triangle.vert +++ b/src/shaders/triangle.vert @@ -1,7 +1,10 @@ #version 460 core layout (location = 0) in vec3 aPos; +out vec4 vertexColor; + void main() { gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); + vertexColor = vec4(aPos.x + 0.5, aPos.y + 0.5, 0.5, 1.0); } \ No newline at end of file