From 31066e789acad4c61b4fc68a6cdf9249b9a44299 Mon Sep 17 00:00:00 2001 From: visil Date: Mon, 9 Oct 2023 11:15:33 +0300 Subject: =?UTF-8?q?=D0=97=D0=BD=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D1=82=D1=8B?= =?UTF-8?q?=D0=B9=20=D1=82=D1=80=D0=B5=D1=83=D0=B3=D0=BE=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson01/a.out | Bin 57456 -> 57360 bytes lesson01/main.cpp | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 28 insertions(+), 15 deletions(-) (limited to 'lesson01') diff --git a/lesson01/a.out b/lesson01/a.out index 885c317..7fca4c0 100755 Binary files a/lesson01/a.out and b/lesson01/a.out differ diff --git a/lesson01/main.cpp b/lesson01/main.cpp index 647674a..1c3804d 100644 --- a/lesson01/main.cpp +++ b/lesson01/main.cpp @@ -5,19 +5,23 @@ const char *vertexShaderSource = "#version 330 core\n" "layout (location = 0) in vec3 aPos;\n" + "layout (location = 1) in vec3 aColor;\n" + "\n" + "out vec3 ourColor;\n" + "\n" "void main()\n" "{\n" - " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" + " gl_Position = vec4(aPos, 1.0);\n" + " ourColor = aColor;" "}\0"; const char *fragmentShaderSource = "#version 330 core\n" "out vec4 FragColor;\n" - "\n" - "uniform vec4 ourColor;" + "in vec3 ourColor;\n" "\n" "void main()\n" "{\n" - " FragColor = ourColor;\n" + " FragColor = vec4(ourColor, 1.0);\n" "}\0"; void framebuffer_size_callback(GLFWwindow* window, int width, int height); @@ -54,14 +58,13 @@ int main() // вершины фигуры float vertices[] = { - -0.5f, -0.5f, 0.0f, - 0.5f, -0.5f, 0.0f, - 0.5f, 0.5f, 0.0f, - -0.5f, 0.5f, 0.0f + // координаты // цвета + -0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, + 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f, }; unsigned int indices[] = { 0, 1, 2, // первый треугольник - 2, 3, 0 // второй треугольник }; @@ -139,10 +142,20 @@ int main() 3, GL_FLOAT, GL_FALSE, - 3 * sizeof(float), + 6 * sizeof(float), (void*)0 ); glEnableVertexAttribArray(0); + glVertexAttribPointer( + 1, + 3, + GL_FLOAT, + GL_FALSE, + 6 * sizeof(float), + (void*)(3* sizeof(float)) + ); + glEnableVertexAttribArray(1); + /* glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); */ while (!glfwWindowShouldClose(window)) { @@ -152,13 +165,13 @@ int main() glClear(GL_COLOR_BUFFER_BIT); // задаём uniform fragment-шейдера - float timeValue = glfwGetTime(); - float greenValue = (sin(timeValue) / 2.0f) + 0.5f; - int vertexColorLocation = glGetUniformLocation(shaderProgram, - "ourColor"); + /* 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); + /* glUniform4f(vertexColorLocation, 0.0f, greenValue, 0.0f, 1.0f); */ glBindVertexArray(VAO); /* glDrawArrays(GL_TRIANGLES, 0, 3); */ -- cgit v1.2.3