From 406df4513f77d6f581032729d89328ac129420dc Mon Sep 17 00:00:00 2001 From: xxxcc Date: Wed, 5 Jul 2023 23:10:56 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=98=E5=88=B6openCV=20logo=EF=BC=8C?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8F=AA=E8=BD=AC=E4=B8=80=E6=AC=A1=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E4=BF=9D=E6=8C=81=E4=B8=8D=E5=8A=A8=E7=9A=84=E6=95=88?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 38751f0..43e39f9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -39,6 +39,59 @@ static void render() { /* CHECK_GL(glEnd()); */ } + +static void renderRing(float x, float y, float radius, float inner_radius, float r, float g, float b, int start, int end) { + constexpr int n = 3600; + constexpr float pi = 3.1415926535897f; + start *= 10; + end *= 10; + + static int cnt = 0; + static int ok = 0; + if (ok) { + cnt = n; + } + else { + cnt += 10; + if (cnt > n) { + cnt -= n; + ok += 1; + } + } + + for (int i = 0; i <= cnt; i++) { + if (start <= end) { + if (i > start && i <= end) continue; + } + else { + if (i > start || i <= end) continue; + } + float angel = i / (float)n * pi * 2; + float angel_next = (i + 1) / (float)n * pi * 2; + glColor3f(r, g, b); + glVertex3f(radius * sinf(angel) + x, radius * cosf(angel) + y, 0.0f); + glVertex3f(radius * sinf(angel_next) + x, radius * cosf(angel_next) + y, 0.0f); + glVertex3f(inner_radius * sinf(angel) + x, inner_radius * cosf(angel) + y, 0.0f); + + glVertex3f(inner_radius * sinf(angel) + x, inner_radius * cosf(angel) + y, 0.0f); + glVertex3f(inner_radius * sinf(angel_next) + x, inner_radius * cosf(angel_next) + y, 0.0f); + glVertex3f(radius * sinf(angel_next) + x, radius * cosf(angel_next) + y, 0.0f); + } +} + +static void renderCVLogo() { + glBegin(GL_TRIANGLES); + float r = 0.4f; + float r_in = 0.4f * r; + + constexpr float sq = 0.43301270189f; + + renderRing(-sq, -0.25f, r, r_in, 0.0f, 1.0f, 0.0f, 30, 90); + renderRing(sq, -0.25f, r, r_in, 0.0f, 0.0f, 1.0f, 330, 30); + renderRing(0.0f, 0.5f, r, r_in, 1.0f, 0.0f, 0.0f, 150, 210); + CHECK_GL(glEnd()); +} + int main() { if (!glfwInit()) { const char *errmsg; @@ -108,7 +161,8 @@ int main() { while (!glfwWindowShouldClose(window)) { // render graphics CHECK_GL(glClear(GL_COLOR_BUFFER_BIT)); - render(); + //render(); + renderCVLogo(); // refresh screen glfwSwapBuffers(window); glfwPollEvents();