簡體   English   中英

禁用OpenGL中的圖像剔除

[英]Disable culling of images in openGL

我正在創建一個具有兩層的圓形球體:
上面有一個光層的人(半徑300)
一層顏色較深(半徑298)

當我在窗口上繪制此球體時,可以正確繪制該球體。

以下代碼並非完全是openGLopenGL人士對其理解不會有任何問題

ofImagesphericImage; 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM