Skip to content

Instantly share code, notes, and snippets.

@mikewesthad
Created March 15, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikewesthad/568da37da89f657f96f0 to your computer and use it in GitHub Desktop.
Save mikewesthad/568da37da89f657f96f0 to your computer and use it in GitHub Desktop.
An ofSketch showing that the order in which transparent objects are drawn in openGL matters
ofEasyCam cam;
void setup() {
ofSetWindowShape(800, 400);
ofSetRectMode(OF_RECTMODE_CENTER);
}
void draw() {
ofEnableBlendMode(OF_BLENDMODE_DISABLED);
ofBackground(ofColor::white);
ofEnableBlendMode(OF_BLENDMODE_ALPHA);
cam.begin();
// Center the camera over the rects
ofTranslate(-150, 0, 0);
// Draw red on blue
ofSetColor(255, 0, 0, 127);
ofRect(0, 0, 100, 200, 200);
ofSetColor(0, 0, 255, 127);
ofRect(0, 0, 0, 200, 200);
// Draw blue on red
ofSetColor(0, 0, 255, 127);
ofRect(300, 0, 100, 200, 200);
ofSetColor(255, 0, 0, 127);
ofRect(300, 0, 0, 200, 200);
cam.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment