Sketch 2015-06-13
void ofApp::setupAnim() {
masker.setup(width, height);
layer1 = masker.newLayer();
layer2 = masker.newLayer();
ofDisableArbTex();
offset = ofRandom(3);
setupImage("foil.png", &img1, &tex1);
setupImage("glass.png", &img2, &tex2);
plane.set(width, height);
plane.setPosition(halfWidth, halfHeight, 0);
plane.setResolution(2, 2);
glitch = false;
alpha = 255;
fadeIn = true;
fadeOut = false;
}
void ofApp::setupImage(string file, ofImage *img, ofTexture *tex) {
img->loadImage(file);
*tex = img->getTextureReference();
tex->setTextureWrap(GL_MIRRORED_REPEAT, GL_MIRRORED_REPEAT);
}
void ofApp::drawLayer(ofTexture *tex) {
plane.mapTexCoords(tx0, ty0, tx1, ty1);
plane.mapTexCoords(tx1, ty1, tx0, ty0);
tex->bind();
plane.draw();
tex->unbind();
}
void ofApp::updateAnim(){
masker.beginLayer(layer1);
{
ofBackground(ofColor::white);
ofSetColor(ofColor::white);
tx0 = ofGetFrameNum() * 0.005;
ty0 = 0;
tx1 = tx0 - 0.015625;
ty1 = ty0 - 0.125;
drawLayer(&tex1);
}
masker.endLayer(layer1);
masker.beginMask(layer1);
{
ofBackground(ofColor::white);
ofSetColor(ofColor::black);
for(int x = 10; x < width; x+=80) {
for(int y = 10; y < height; y+=80) {
ofRect(x, y, 60, 60);
}
}
}
masker.endMask(layer1);
masker.beginLayer(layer2);
{
ofSetColor(ofColor::white);
tx0 = 0;
ty0 = ofGetFrameNum() * 0.01;
tx1 = tx0 - 2;
ty1 = ty0 - 0.5;
drawLayer(&tex2);
}
masker.endLayer(layer2);
masker.beginMask(layer2);
{
masker.drawLayer(layer1);
ofSetColor(ofColor::white);
for(int x = 10; x < width; x+=80) {
for(int y = 10; y < height; y+=80) {
ofRect(x, y, 60, 60);
}
}
}
masker.endMask(layer2);
}
void ofApp::drawAnim() {
ofBackground(ofColor::black);
if(glitch) {
masker.draw();
if(ofRandom(1) > 0.4) {
glitch = !glitch;
}
} else {
masker.drawLayer(layer2);
if(ofRandom(1) > 0.9) {
glitch = !glitch;
}
}
if(fadeIn) {
alpha -= 40;
if(alpha <= 0) fadeIn = false;
}
if(fadeOut) {
alpha += 40;
if(alpha >= 355) {
renderGif();
}
}
ofSetColor(ofColor::black, alpha);
ofRect(0, 0, width, height);
if(ofGetFrameNum() == 70) {
fadeOut = true;
}
}
What on earth is going on with these masks?