From b61075f11c3e1dec60ca4cf56660f3457f8327a4 Mon Sep 17 00:00:00 2001 From: SuperStrongSuctionMonster <6080248@qq.com> Date: Mon, 3 Jul 2023 23:23:53 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E7=94=BB=E4=BA=86OpenCV=20logo=E3=80=82=E5=B0=8F?= =?UTF-8?q?=E5=BD=AD=E8=80=81=E5=B8=88=E8=BE=9B=E8=8B=A6=E4=BA=86=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 87 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 28 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 38751f0..d4125ff 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,37 +6,64 @@ #include #include #include +#include + +void plotCircle(std::vector center, float radius, std::vector color, float depth) +{ + constexpr int iter = 300; + constexpr float pi = 3.1415926535897f; + glColor3f(color.at(0), color.at(1), color.at(2)); + for (int i = 0; i < iter; i++) { + float angle = i / (float)iter * pi * 2; + float angle_next = (i + 1) / (float)iter * pi * 2; + glVertex3f(center.at(0), center.at(1), center.at(2)); + glVertex3f(center.at(0) + radius * sinf(angle), center.at(1) + radius * cosf(angle), depth); + glVertex3f(center.at(0) + radius * sinf(angle_next), center.at(1) + radius * cosf(angle_next), depth); + } +} static void render() { - glBegin(GL_TRIANGLES); - glColor3f(1.0f, 0.0f, 0.0f); - glVertex3f(0.0f, 0.5f, 0.0f); - glColor3f(0.0f, 1.0f, 0.0f); - glVertex3f(-0.5f, -0.5f, 0.0f); - glColor3f(0.0f, 0.0f, 1.0f); - glVertex3f(0.5f, -0.5f, 0.0f); + glBegin(GL_TRIANGLES); + constexpr int n = 300; + constexpr float pi = 3.1415926535897f; + float radius = 0.3f; + float inner_radius = 0.15f; + static int x = 0; + std::vector green_color{.0f, 1.0f, .0f}; + std::vector red_color{1.0f, .0f, .0f}; + std::vector blue_color{ .0f, .0f, 1.0f }; + std::vector black_color{ .0f, .0f, 0.0f }; + std::vector green_circle_center{-0.4f, -0.4f, 1.0f}; + std::vector red_circle_center{0.0f, 0.4f, 1.0f}; + std::vector blue_circle_center{0.4f, -0.4f, 1.0f}; + //Circles + plotCircle(green_circle_center, radius, green_color, 0.9f); + plotCircle(red_circle_center, radius, red_color, 0.9f); + for (int i = 0; i < n; i++) { + float angle = i / (float)n * pi * 2; + float angle_next = (i + 1) / (float)n * pi * 2; + if (angle > pi / 6 && angle < pi * 11 / 6) + { + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(blue_circle_center.at(0), blue_circle_center.at(1), 0.5f); + glVertex3f(blue_circle_center.at(0) + radius * sinf(angle), blue_circle_center.at(1) + radius * cosf(angle), 0.5f); + glVertex3f(blue_circle_center.at(0) + radius * sinf(angle_next), blue_circle_center.at(1) + radius * cosf(angle_next), 0.5f); + } + else + { + continue; + } + } + plotCircle(green_circle_center, inner_radius, black_color, -0.1f); + plotCircle(red_circle_center, inner_radius, black_color, -0.1f); + plotCircle(blue_circle_center, inner_radius, black_color, -0.1f); + //Black Triangle + glColor3f(0.0f, 0.0f, 0.0f); + glVertex3f(green_circle_center.at(0), green_circle_center.at(1), 0.6f); + glVertex3f(red_circle_center.at(0), red_circle_center.at(1), 0.6f); + glVertex3f(blue_circle_center.at(0), blue_circle_center.at(1), 0.6f); + CHECK_GL(glEnd()); - /* glBegin(GL_TRIANGLES); */ - /* constexpr int n = 100; */ - /* constexpr float pi = 3.1415926535897f; */ - /* float radius = 0.5f; */ - /* float inner_radius = 0.25f; */ - /* static int x = 0; */ - /* x++; */ - /* if (x > n) */ - /* x -= n; */ - /* for (int i = 0; i < x; i++) { */ - /* float angle = i / (float)n * pi * 2; */ - /* float angle_next = (i + 1) / (float)n * pi * 2; */ - /* glVertex3f(0.0f, 0.0f, 0.0f); */ - /* glVertex3f(radius * sinf(angle), radius * cosf(angle), 0.0f); */ - /* glVertex3f(radius * sinf(angle_next), radius * cosf(angle_next), 0.0f); */ - /* glVertex3f(inner_radius * sinf(angle), inner_radius * cosf(angle), 0.0f); */ - /* glVertex3f(inner_radius * sinf(angle_next), inner_radius * cosf(angle_next), 0.0f); */ - /* glVertex3f(inner_radius * sinf(angle), inner_radius * cosf(angle), 0.0f); */ - /* glVertex3f(radius * sinf(angle_next), radius * cosf(angle_next), 0.0f); */ - /* } */ - /* CHECK_GL(glEnd()); */ } int main() { @@ -103,11 +130,15 @@ int main() { CHECK_GL(glEnable(GL_BLEND)); CHECK_GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); CHECK_GL(glPointSize(64.0f)); + CHECK_GL(glEnable(GL_DEPTH_TEST)); + CHECK_GL(glDepthMask(GL_TRUE)); // start main game loop while (!glfwWindowShouldClose(window)) { // render graphics CHECK_GL(glClear(GL_COLOR_BUFFER_BIT)); + CHECK_GL(glClearDepth(1.0f)); + CHECK_GL(glClear(GL_DEPTH_BUFFER_BIT)); render(); // refresh screen glfwSwapBuffers(window); From f502d112b2994bf47ce121870db8b62420bffac0 Mon Sep 17 00:00:00 2001 From: CC33XXX <6080248@qq.com> Date: Mon, 3 Jul 2023 23:27:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?Revert=20"=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=94=BB=E4=BA=86OpenCV=20logo=E3=80=82?= =?UTF-8?q?=E5=B0=8F=E5=BD=AD=E8=80=81=E5=B8=88=E8=BE=9B=E8=8B=A6=E4=BA=86?= =?UTF-8?q?=EF=BC=81"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b61075f11c3e1dec60ca4cf56660f3457f8327a4. --- src/main.cpp | 87 +++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 59 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d4125ff..38751f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,64 +6,37 @@ #include #include #include -#include - -void plotCircle(std::vector center, float radius, std::vector color, float depth) -{ - constexpr int iter = 300; - constexpr float pi = 3.1415926535897f; - glColor3f(color.at(0), color.at(1), color.at(2)); - for (int i = 0; i < iter; i++) { - float angle = i / (float)iter * pi * 2; - float angle_next = (i + 1) / (float)iter * pi * 2; - glVertex3f(center.at(0), center.at(1), center.at(2)); - glVertex3f(center.at(0) + radius * sinf(angle), center.at(1) + radius * cosf(angle), depth); - glVertex3f(center.at(0) + radius * sinf(angle_next), center.at(1) + radius * cosf(angle_next), depth); - } -} static void render() { - glBegin(GL_TRIANGLES); - constexpr int n = 300; - constexpr float pi = 3.1415926535897f; - float radius = 0.3f; - float inner_radius = 0.15f; - static int x = 0; - std::vector green_color{.0f, 1.0f, .0f}; - std::vector red_color{1.0f, .0f, .0f}; - std::vector blue_color{ .0f, .0f, 1.0f }; - std::vector black_color{ .0f, .0f, 0.0f }; - std::vector green_circle_center{-0.4f, -0.4f, 1.0f}; - std::vector red_circle_center{0.0f, 0.4f, 1.0f}; - std::vector blue_circle_center{0.4f, -0.4f, 1.0f}; - //Circles - plotCircle(green_circle_center, radius, green_color, 0.9f); - plotCircle(red_circle_center, radius, red_color, 0.9f); - for (int i = 0; i < n; i++) { - float angle = i / (float)n * pi * 2; - float angle_next = (i + 1) / (float)n * pi * 2; - if (angle > pi / 6 && angle < pi * 11 / 6) - { - glColor3f(0.0f, 0.0f, 1.0f); - glVertex3f(blue_circle_center.at(0), blue_circle_center.at(1), 0.5f); - glVertex3f(blue_circle_center.at(0) + radius * sinf(angle), blue_circle_center.at(1) + radius * cosf(angle), 0.5f); - glVertex3f(blue_circle_center.at(0) + radius * sinf(angle_next), blue_circle_center.at(1) + radius * cosf(angle_next), 0.5f); - } - else - { - continue; - } - } - plotCircle(green_circle_center, inner_radius, black_color, -0.1f); - plotCircle(red_circle_center, inner_radius, black_color, -0.1f); - plotCircle(blue_circle_center, inner_radius, black_color, -0.1f); - //Black Triangle - glColor3f(0.0f, 0.0f, 0.0f); - glVertex3f(green_circle_center.at(0), green_circle_center.at(1), 0.6f); - glVertex3f(red_circle_center.at(0), red_circle_center.at(1), 0.6f); - glVertex3f(blue_circle_center.at(0), blue_circle_center.at(1), 0.6f); - + glBegin(GL_TRIANGLES); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(0.0f, 0.5f, 0.0f); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(-0.5f, -0.5f, 0.0f); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(0.5f, -0.5f, 0.0f); CHECK_GL(glEnd()); + /* glBegin(GL_TRIANGLES); */ + /* constexpr int n = 100; */ + /* constexpr float pi = 3.1415926535897f; */ + /* float radius = 0.5f; */ + /* float inner_radius = 0.25f; */ + /* static int x = 0; */ + /* x++; */ + /* if (x > n) */ + /* x -= n; */ + /* for (int i = 0; i < x; i++) { */ + /* float angle = i / (float)n * pi * 2; */ + /* float angle_next = (i + 1) / (float)n * pi * 2; */ + /* glVertex3f(0.0f, 0.0f, 0.0f); */ + /* glVertex3f(radius * sinf(angle), radius * cosf(angle), 0.0f); */ + /* glVertex3f(radius * sinf(angle_next), radius * cosf(angle_next), 0.0f); */ + /* glVertex3f(inner_radius * sinf(angle), inner_radius * cosf(angle), 0.0f); */ + /* glVertex3f(inner_radius * sinf(angle_next), inner_radius * cosf(angle_next), 0.0f); */ + /* glVertex3f(inner_radius * sinf(angle), inner_radius * cosf(angle), 0.0f); */ + /* glVertex3f(radius * sinf(angle_next), radius * cosf(angle_next), 0.0f); */ + /* } */ + /* CHECK_GL(glEnd()); */ } int main() { @@ -130,15 +103,11 @@ int main() { CHECK_GL(glEnable(GL_BLEND)); CHECK_GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); CHECK_GL(glPointSize(64.0f)); - CHECK_GL(glEnable(GL_DEPTH_TEST)); - CHECK_GL(glDepthMask(GL_TRUE)); // start main game loop while (!glfwWindowShouldClose(window)) { // render graphics CHECK_GL(glClear(GL_COLOR_BUFFER_BIT)); - CHECK_GL(glClearDepth(1.0f)); - CHECK_GL(glClear(GL_DEPTH_BUFFER_BIT)); render(); // refresh screen glfwSwapBuffers(window); From a37a5865492f8faaea5b81ac29bdd730d7d9a3a7 Mon Sep 17 00:00:00 2001 From: CC33XXX <6080248@qq.com> Date: Mon, 3 Jul 2023 23:29:13 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E4=BD=9C?= =?UTF-8?q?=E4=B8=9A=E7=94=BB=E4=BA=86OpenCV=20logo=E3=80=82=E5=B0=8F?= =?UTF-8?q?=E5=BD=AD=E8=80=81=E5=B8=88=E8=BE=9B=E8=8B=A6=E4=BA=86=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 97 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 38751f0..edd7d02 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,42 +6,69 @@ #include #include #include +#include + +void plotCircle(std::vector center, float radius, std::vector color, float depth) +{ + constexpr int iter = 300; + constexpr float pi = 3.1415926535897f; + glColor3f(color.at(0), color.at(1), color.at(2)); + for (int i = 0; i < iter; i++) { + float angle = i / (float)iter * pi * 2; + float angle_next = (i + 1) / (float)iter * pi * 2; + glVertex3f(center.at(0), center.at(1), center.at(2)); + glVertex3f(center.at(0) + radius * sinf(angle), center.at(1) + radius * cosf(angle), depth); + glVertex3f(center.at(0) + radius * sinf(angle_next), center.at(1) + radius * cosf(angle_next), depth); + } +} static void render() { glBegin(GL_TRIANGLES); - glColor3f(1.0f, 0.0f, 0.0f); - glVertex3f(0.0f, 0.5f, 0.0f); - glColor3f(0.0f, 1.0f, 0.0f); - glVertex3f(-0.5f, -0.5f, 0.0f); - glColor3f(0.0f, 0.0f, 1.0f); - glVertex3f(0.5f, -0.5f, 0.0f); + constexpr int n = 300; + constexpr float pi = 3.1415926535897f; + float radius = 0.3f; + float inner_radius = 0.15f; + static int x = 0; + std::vector green_color{.0f, 1.0f, .0f}; + std::vector red_color{1.0f, .0f, .0f}; + std::vector blue_color{ .0f, .0f, 1.0f }; + std::vector black_color{ .0f, .0f, 0.0f }; + std::vector green_circle_center{-0.4f, -0.4f, 1.0f}; + std::vector red_circle_center{0.0f, 0.4f, 1.0f}; + std::vector blue_circle_center{0.4f, -0.4f, 1.0f}; + //Circles + plotCircle(green_circle_center, radius, green_color, 0.9f); + plotCircle(red_circle_center, radius, red_color, 0.9f); + for (int i = 0; i < n; i++) { + float angle = i / (float)n * pi * 2; + float angle_next = (i + 1) / (float)n * pi * 2; + if (angle > pi / 6 && angle < pi * 11 / 6) + { + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(blue_circle_center.at(0), blue_circle_center.at(1), 0.5f); + glVertex3f(blue_circle_center.at(0) + radius * sinf(angle), blue_circle_center.at(1) + radius * cosf(angle), 0.5f); + glVertex3f(blue_circle_center.at(0) + radius * sinf(angle_next), blue_circle_center.at(1) + radius * cosf(angle_next), 0.5f); + } + else + { + continue; + } + } + plotCircle(green_circle_center, inner_radius, black_color, -0.1f); + plotCircle(red_circle_center, inner_radius, black_color, -0.1f); + plotCircle(blue_circle_center, inner_radius, black_color, -0.1f); + //Black Triangle + glColor3f(0.0f, 0.0f, 0.0f); + glVertex3f(green_circle_center.at(0), green_circle_center.at(1), 0.6f); + glVertex3f(red_circle_center.at(0), red_circle_center.at(1), 0.6f); + glVertex3f(blue_circle_center.at(0), blue_circle_center.at(1), 0.6f); + CHECK_GL(glEnd()); - /* glBegin(GL_TRIANGLES); */ - /* constexpr int n = 100; */ - /* constexpr float pi = 3.1415926535897f; */ - /* float radius = 0.5f; */ - /* float inner_radius = 0.25f; */ - /* static int x = 0; */ - /* x++; */ - /* if (x > n) */ - /* x -= n; */ - /* for (int i = 0; i < x; i++) { */ - /* float angle = i / (float)n * pi * 2; */ - /* float angle_next = (i + 1) / (float)n * pi * 2; */ - /* glVertex3f(0.0f, 0.0f, 0.0f); */ - /* glVertex3f(radius * sinf(angle), radius * cosf(angle), 0.0f); */ - /* glVertex3f(radius * sinf(angle_next), radius * cosf(angle_next), 0.0f); */ - /* glVertex3f(inner_radius * sinf(angle), inner_radius * cosf(angle), 0.0f); */ - /* glVertex3f(inner_radius * sinf(angle_next), inner_radius * cosf(angle_next), 0.0f); */ - /* glVertex3f(inner_radius * sinf(angle), inner_radius * cosf(angle), 0.0f); */ - /* glVertex3f(radius * sinf(angle_next), radius * cosf(angle_next), 0.0f); */ - /* } */ - /* CHECK_GL(glEnd()); */ } int main() { if (!glfwInit()) { - const char *errmsg; + const char* errmsg; glfwGetError(&errmsg); if (!errmsg) errmsg = "(no error)"; std::cerr << "failed to initialize GLFW: " << errmsg << '\n'; @@ -61,18 +88,20 @@ int main() { } // Create window - GLFWwindow *window = glfwCreateWindow(640, 640, "Example", NULL, NULL); + GLFWwindow* window = glfwCreateWindow(640, 640, "Example", NULL, NULL); if (!window) { - const char *errmsg; + const char* errmsg; glfwGetError(&errmsg); if (!errmsg) errmsg = "(no error)"; std::cerr << "GLFW failed to create window: " << errmsg << '\n'; std::cerr << "==============================================\n"; if (!strcmp(errmsg, "X11: The DISPLAY environment variable is missing")) { std::cerr << "You seems not running with graphic display\n"; - } else if (!strcmp(errmsg, "WGL: The driver does not appear to support OpenGL")) { + } + else if (!strcmp(errmsg, "WGL: The driver does not appear to support OpenGL")) { std::cerr << "Please consider install an OpenGL driver, or use the mesa driver\n"; - } else if (!strcmp(errmsg, "WGL: Failed to create OpenGL context")) { + } + else if (!strcmp(errmsg, "WGL: Failed to create OpenGL context")) { std::cerr << "Your driver seems not supporting the required OpenGL version\n"; } std::cerr << "- If you have a physical graphic card (e.g. NVIDIA), install it from your graphic card vendor official website: http://www.nvidia.com/Download/index.aspx\n"; @@ -103,11 +132,15 @@ int main() { CHECK_GL(glEnable(GL_BLEND)); CHECK_GL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); CHECK_GL(glPointSize(64.0f)); + CHECK_GL(glEnable(GL_DEPTH_TEST)); + CHECK_GL(glDepthMask(GL_TRUE)); // start main game loop while (!glfwWindowShouldClose(window)) { // render graphics CHECK_GL(glClear(GL_COLOR_BUFFER_BIT)); + CHECK_GL(glClearDepth(1.0f)); + CHECK_GL(glClear(GL_DEPTH_BUFFER_BIT)); render(); // refresh screen glfwSwapBuffers(window); From 17ed4a52d2cb507eddc84b7d79ebf617b74d0b95 Mon Sep 17 00:00:00 2001 From: CC33XXX <6080248@qq.com> Date: Mon, 3 Jul 2023 23:50:27 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=94=B9=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E4=BD=9C=E4=B8=9Abug=E3=80=82=E3=80=82=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index edd7d02..cbbaf66 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ void plotCircle(std::vector center, float radius, std::vector colo for (int i = 0; i < iter; i++) { float angle = i / (float)iter * pi * 2; float angle_next = (i + 1) / (float)iter * pi * 2; - glVertex3f(center.at(0), center.at(1), center.at(2)); + glVertex3f(center.at(0), center.at(1), depth); glVertex3f(center.at(0) + radius * sinf(angle), center.at(1) + radius * cosf(angle), depth); glVertex3f(center.at(0) + radius * sinf(angle_next), center.at(1) + radius * cosf(angle_next), depth); }