简体   繁体   中英

Disable culling of images in openGL

I am creating a circlular sphere with two layers:
one having the light layer above (radius 300)
one having the darker color layer (radius 298)

When I draw this sphere on my window, I get the sphere drawn properly.

The following code is not exactly openGL but the openGL folks won't have any problem understanding it

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

However, the problem is at some portions, the front image (lighter one) actually overidies/covers the back spherical image (and the darker portion is not fully visible). When the sphere is rotated with the camera, sometimes the region becomes visible depending on the rotation angles/axis. I want to disable this so that the kind of effect does not take place.

I was earlier thinking if this is related to face-cullin in openGL but I disbaled by setting glDisable(GL_CULL_FACE) and it didn't have any effect. glEnable(GL_DEPTH_TEST); is also set. Any suggestions on how I could disable this so that both the spherical images are visible?

Your problem is, that blending of translucent surfaces is not depth order independent. When blending is enabled you must sort your faces far to near to make this work. The depth buffer won't help you there.

Luckily if your shapes are convex sorting can be done by drawing each convex shape 2 times. One time with front faces being culled (this draws the far away backside faces), then with back face cullung (only the near front faces are drawn). If you arrange geometry in a matroshka like fashion you first work yourself outside inward with front faces being culled, and then outward again with back faces being culled.

Modifying your code it would look like this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM