Quantcast
Viewing all articles
Browse latest Browse all 40524

Alpha channel(transparency) is not working? Transparent ellipse completely masks a box

Hi there!

It's not a bug, it's the way OpenGL works, regarding translucency and the depth buffer. Basically:

In order to achieve translucency, all opaque objects must be drawn before drawing any translucent ones.

(From the OpenGL Wiki — Transparency Sorting)

So, all you have to do is:

ofPushMatrix();
ofEnableDepthTest();
ofTranslate(ofGetWidth()/2, ofGetHeight()/2, 0);
ofRotateY(mouseX);

ofSetColor(ofColor::yellow);
ofDrawBox(0, 0, -50, 10, 10, 10);

ofSetColor(ofColor::orange);
ofDrawBox(0, 0, 50, 10, 10, 10);

ofSetColor(255, 0, 0, 10);
ofDrawEllipse(0, 0, 0, 100, 100);

ofDisableDepthTest();
ofPopMatrix();

Viewing all articles
Browse latest Browse all 40524

Trending Articles