From b210fc71438d31cb5cbc434bf9b8db4b7164e3c8 Mon Sep 17 00:00:00 2001 From: visil Date: Mon, 9 Oct 2023 11:02:54 +0300 Subject: =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=86=D0=B2=D0=B5=D1=82=D0=B0=20=D0=BE=D1=82=20=D0=B2=D1=80?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson01/a.out | Bin 57360 -> 57456 bytes lesson01/main.cpp | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lesson01/a.out b/lesson01/a.out index 3e9babe..885c317 100755 Binary files a/lesson01/a.out and b/lesson01/a.out 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 #include #include +#include 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); -- cgit v1.2.3