禁用在openGL中剔除图像

时间:2012-12-31 08:39:33

标签: c++ algorithm opengl

我正在创建一个有两层的圆形球体:
一个具有上面的光层(半径300)
一个具有较暗的颜色层(半径298)

当我在窗口上绘制这个球体时,我会正确绘制球体。

以下代码并不完全是openGL,但openGL人员在理解它时不会有任何问题

ofImage sphericalImage; GLUquadricObj * quadric;

ofPushMatrix();

    //Sphere dark image
    ofRotateX(90);
    ofPushStyle();
    ofSetColor(43,64,105);
    sphericalImage.getTextureReference().bind();
    gluSphere(quadric, 298, 100, 100);
    ofPopStyle();

    //Sphere light image
    ofPushStyle();
    ofSetColor(255,255,255);
    sphericalImage.getTextureReference().bind();
    gluSphere(quadric, 300, 100, 100);
    ofPopStyle();
    sphericalImage.unbind();

ofPopMatrix();

然而,问题是在某些部分,前图像(较亮的图像)实际上覆盖/覆盖后球面图像(并且较暗部分不完全可见)。当球体与相机一起旋转时,根据旋转角度/轴,有时该区域变得可见。我想禁用它,以便不会发生这种效果。

我之前想过,如果这与openGL中的face-cullin有关,但是我通过设置glDisable(GL_CULL_FACE)来解除它并且它没有任何效果。 glEnable(GL_DEPTH_TEST);也已设定。有关如何禁用此功能的任何建议,以便两个球形图像都可见?

1 个答案:

答案 0 :(得分:4)

您的问题是,半透明表面的混合不是与深度顺序无关的。启用混合后,您必须将面部分类到远处以使其工作。深度缓冲区对你没有帮助。

幸运的是,如果你的形状是凸的,可以通过绘制每个凸形状2次来完成。有一次正面被剔除(这会吸引远处的背面),然后背面c((只画出近前面)。如果你以类似matroshka的方式排列几何形状,你首先要在外面向前工作,前脸被剔除,然后再向外,背面被剔除。

修改代码看起来像这样

glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);

//Globe light image
ofPushStyle();
ofSetColor(255,255,255);
sphericalImage.getTextureReference().bind();
gluSphere(quadric, 300, 100, 100);
ofPopStyle();
sphericalImage.unbind(); 

//Sphere dark image
ofRotateX(90);
ofPushStyle();
ofSetColor(43,64,105);
sphericalImage.getTextureReference().bind();
gluSphere(quadric, 298, 100, 100);

glCullFace(GL_BACK);

gluSphere(quadric, 298, 100, 100);
ofPopStyle();

//Globe light image
ofPushStyle();
ofSetColor(255,255,255);
sphericalImage.getTextureReference().bind();
gluSphere(quadric, 300, 100, 100);
ofPopStyle();
sphericalImage.unbind();