0

AopenGL を使用して描画された 3d の文字があります。私はそれを段階的に描きます - 2D文字Aを描き、2D文字Aをzオフセットで描き、辺を描き、下の長方形を描きます。結果は次のようになります ここに画像の説明を入力

問題は、文字の右側の色が見えることです->左側のポリゴンが透明に見えます側面の初期化順序を切り替えると(左->右)、次のようになります ここに画像の説明を入力

文字を回転させる必要がなければ問題ありませんでした。回転中、右側は透明です(など)。 ポリゴンにはどのモードを使用すればよいですか?

こんな感じで文字を描きます

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