0

我有一个 3d 字母A,使用 openGL 绘制。我一步一步地画它——画二维字母A,画二维字母Az偏移,画边,画底部矩形等。结果看起来像这样 在此处输入图像描述

问题是我可以看到字母右侧的颜色->左侧的多边形看起来像透明当我切换边的初始化顺序(左->右)时,它看起来像这样 在此处输入图像描述

如果我不需要旋转字母,这不是问题。在旋转过程中,右侧是透明的(等等)。 我应该对多边形使用什么模式?

我这样画信

void drawLetter(float offset, float *color) {

Point p2_next = p2;
p2_next.z -= offset;
Point p7_next = p7;
p7_next.z -= offset;
Point p1_next = p1;
p1_next.z -= offset;

Point main_polygon[] = { p2_next, p7_next, p1_next };
Point norm = normal(main_polygon);

glNormal3f(norm.x, norm.y, norm.z);
//p1, p2, p3, p10
glBegin(GL_POLYGON);
    glColor3fv(color);
    glVertex3f(p1.x, p1.y, p1.z - offset);
    glVertex3f(p2.x, p2.y, p2.z - offset);
    glVertex3f(p3.x, p3.y, p3.z - offset);
    glVertex3f(p10.x, p10.y, p10.z - offset);
glEnd();

//p1, p10, p6, p7
glBegin(GL_POLYGON);
    glColor3fv(color);
    glVertex3f(p1.x, p1.y, p1.z - offset);
    glVertex3f(p10.x, p10.y, p10.z - offset);
    glVertex3f(p6.x, p6.y, p6.z - offset);
    glVertex3f(p7.x, p7.y, p7.z - offset);
glEnd();

//p8, p4, p5, p9
glBegin(GL_POLYGON);
    glColor3fv(color);
    glVertex3f(p8.x, p8.y, p8.z - offset);
    glVertex3f(p4.x, p4.y, p4.z - offset);
    glVertex3f(p5.x, p5.y, p5.z - offset);
    glVertex3f(p9.x, p9.y, p9.z - offset);
glEnd();

}

(还有边、底部矩形等的功能).z 例如drawSides

void drawSides(float offset, Point pa, Point pb, float *color) {

Point p1_next = pa;
Point p2_next = pa;
p2_next.z -= offset;
Point p3_next = pb;

Point main_polygon[] = { p1_next, p2_next, p3_next };
Point norm = normal(main_polygon);

glNormal3f(norm.x, norm.y, norm.z);
//p1, p7
glBegin(GL_POLYGON);
    glColor3fv(color);
    glVertex3f(pa.x, pa.y, pa.z);
    glVertex3f(pa.x, pa.y, pa.z - offset);
    glVertex3f(pb.x, pb.y, pb.z - offset);
    glVertex3f(pb.x, pb.y, pb.z);
glEnd();

}

这是我的绘图功能

void display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

axes();
    if (angle > 180) angle = 0; 
    if (angle < 0) angle = 360;

glPushMatrix();
    glLightfv(GL_LIGHT0, GL_POSITION, LIGHT);

    glRotatef(angle, 0.0, 1.0, 0.0);

    drawLetter(offset, color_letter);
    drawRibs(offset);

    drawBottoms(offset, p2, p3, bottom);
    drawRibsExt(offset, p2, p3);

    drawBottoms(offset, p3, p4, side_left);
    drawRibsExt(offset, p3, p4);

    drawBottoms(offset, p4, p5, side_right);
    drawRibsExt(offset, p4, p5);

    drawBottoms(offset, p5, p6, side_left);
    drawRibsExt(offset, p5, p6);

    drawBottoms(offset, p6, p7, bottom);
    drawRibsExt(offset, p6, p7);

    drawBottoms(offset, p8, p9, side_left);
    drawRibsExt(offset, p8, p9);

    drawBottoms(offset, p9, p10, side_left);
    drawRibsExt(offset, p9, p10);

    drawBottoms(offset, p10, p8, side_left);
    drawRibsExt(offset, p10, p8);

    drawSides(offset, p2, p1, side_left); //switch -> right is transparent
    drawSides(offset, p7, p1, side_right); //switch -> left is transparent

    drawLetter(0, color_letter);
    drawRibs(0);

glPopMatrix();

glutSwapBuffers();
glFlush();
}
4

0 回答 0