diff --git a/src/main.cc b/src/main.cc index 039ef8a..5ede541 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,7 @@ #include #include #include +#include void framebuffer_size_callback(GLFWwindow* window, int width, int height); void process_input(GLFWwindow* window); @@ -11,11 +12,9 @@ const char* vertexShaderCode = R"( // Set the GLSL version to 3.3 and use the OpenGL core profile #version 330 core layout (location = 0) in vec3 aPos; -out vec4 vertexColor; void main() { gl_Position = vec4(aPos, 1.0); - vertexColor = vec4(0.5, 0.0, 0.0, 1.0); } )"; @@ -23,10 +22,11 @@ const char* fragmentShaderCode = R"( // Set the GLSL version to 3.3 and use the OpenGL core profile #version 330 core out vec4 FragColor; -in vec4 vertexColor; + +uniform vec4 ourColor; void main() { - FragColor = vertexColor; + FragColor = ourColor; } )"; @@ -221,6 +221,13 @@ int main() { // Use the shaderProgram shader program for drawing verticies. glUseProgram(shaderProgram); + + // Change the uniform color. + float timeValue = glfwGetTime(); + float greenValue = (std::sin(timeValue) / 2.0f) + 0.5f; + int vertexColorLocation = glGetUniformLocation(shaderProgram, "ourColor"); + glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f); + if (!rectangleToggled) { // Bind the state to use the vertexArrayObject object so OpenGL knows what to do with the verticies. glBindVertexArray(triangleRenderObjs->vertexArrayObject);