summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvisil <workregor@mail.ru>2023-10-09 11:02:54 +0300
committervisil <workregor@mail.ru>2023-10-09 11:02:54 +0300
commitb210fc71438d31cb5cbc434bf9b8db4b7164e3c8 (patch)
tree939ae99a7b5f1e0598e3bddf57c66a9dc88fe74e
parent1df02dd268685da10032974ecfdc3f229dc166a3 (diff)
Изменение цвета от времени
-rwxr-xr-xlesson01/a.outbin57360 -> 57456 bytes
-rw-r--r--lesson01/main.cpp15
2 files changed, 13 insertions, 2 deletions
diff --git a/lesson01/a.out b/lesson01/a.out
index 3e9babe..885c317 100755
--- a/lesson01/a.out
+++ b/lesson01/a.out
Binary files differ
diff --git a/lesson01/main.cpp b/lesson01/main.cpp
index 9182d58..647674a 100644
--- a/lesson01/main.cpp
+++ b/lesson01/main.cpp
@@ -1,6 +1,7 @@
#include <glad/glad.h>
#include <iostream>
#include <GLFW/glfw3.h>
+#include <cmath>
const char *vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
@@ -12,9 +13,11 @@ const char *vertexShaderSource = "#version 330 core\n"
const char *fragmentShaderSource = "#version 330 core\n"
"out vec4 FragColor;\n"
"\n"
+ "uniform vec4 ourColor;"
+ "\n"
"void main()\n"
"{\n"
- " FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
+ " FragColor = ourColor;\n"
"}\0";
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
@@ -141,14 +144,22 @@ int main()
);
glEnableVertexAttribArray(0);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ /* glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); */
while (!glfwWindowShouldClose(window)) {
processInput(window);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
+
+ // задаём uniform fragment-шейдера
+ float timeValue = glfwGetTime();
+ float greenValue = (sin(timeValue) / 2.0f) + 0.5f;
+ int vertexColorLocation = glGetUniformLocation(shaderProgram,
+ "ourColor");
glUseProgram(shaderProgram);
+ glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f);
+
glBindVertexArray(VAO);
/* glDrawArrays(GL_TRIANGLES, 0, 3); */
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);