gpt4 book ai didi

c++ - 在 openGL 中禁用图像剔除

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:39:16 25 4
gpt4 key购买 nike

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

当我在我的窗口上绘制这个球体时,我得到了正确绘制的球体。

下面的代码不完全是 openGLopenGL 的人理解它不会有任何问题

ofImage sphericalImage;GLUquadricObj *二次;

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 中的面部剔除有关,但我通过设置 glDisable(GL_CULL_FACE) 取消了它并且没有任何效果。 glEnable(GL_DEPTH_TEST); 也已设置。关于如何禁用此功能以使两个球形图像都可见的任何建议?

最佳答案

您的问题是,半透明表面的混合与深度顺序无关。启用混合后,您必须将脸部从远到近排序才能完成此操作。深度缓冲区在那里帮不了你。

幸运的是,如果您的形状是凸形,则可以通过绘制每个凸形 2 次来完成排序。一次剔除正面(这会绘制远处的背面),然后剔除背面(只绘制近的正面)。如果你像时尚一样在 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();

关于c++ - 在 openGL 中禁用图像剔除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14099417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com