Skip to content

完成作业,画openGL的LOGO图 #34

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,74 @@
#include <cstring>
#include <cstdlib>

struct pos {
float x;
float y;
};

struct color {
float r;
float g;
float b;
};

struct skipIndex {
int small;
int big;
};


static void drawLogo(const pos& pos,const color& color,const skipIndex& skip) {
constexpr int n = 100;

glColor3f(color.r, color.g, color.b);
glBegin(GL_TRIANGLES);

constexpr float pi = 3.1415926535897f;
float radius = 0.3f;
float inner_radius = 0.15f;

bool twoPart = false;
skipIndex sk1 = skip;
skipIndex sk2 = skipIndex{ 0, 0 };
if (skip.small > skip.big) {
sk1.big = 100;
sk2.small = 0;
sk2.big = skip.big;

twoPart = true;
}

for (int i = 0; i < n; i++) {
if (i <= sk1.big && i >= sk1.small) {
continue;
}

if (twoPart && i < sk2.big && i >= sk2.small) {
continue;
}

float angle = i / (float)n * pi * 2;
float angle_next = (i + 1) / (float)n * pi * 2;

glVertex3f(pos.x + radius * sinf(angle), pos.y + radius * cosf(angle), 0.0f);
glVertex3f(pos.x + radius * sinf(angle_next), pos.y + radius * cosf(angle_next), 0.0f);
glVertex3f(pos.x + inner_radius * sinf(angle), pos.y + inner_radius * cosf(angle), 0.0f);

glVertex3f(pos.x + radius * sinf(angle_next), pos.y + radius * cosf(angle_next), 0.0f);
glVertex3f(pos.x + inner_radius * sinf(angle), pos.y + inner_radius * cosf(angle), 0.0f);
glVertex3f(pos.x + inner_radius * sinf(angle_next), pos.y + inner_radius * cosf(angle_next), 0.0f);

}
CHECK_GL(glEnd());
}

static void render() {
drawLogo(pos{ 0.0f,0.5f }, color{ 1.0f,0.0f,0.0f }, skipIndex{40,60});
drawLogo(pos{ -0.5f,-0.25f }, color{ 0.0f,1.0f,0.0f }, skipIndex{ 10,24 });
drawLogo(pos{ 0.5f,-0.25f }, color{ 0.0f,0.0f,1.0f }, skipIndex{90,10 });
}
static void render2() {
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
Expand Down