Giter Club home page Giter Club logo

ofxlayermask's Introduction

ofxLayerMask

This addon makes it easy to draw a graphical layer, and then hide parts of that layer with a mask. It operates on the same principles as layer masking in Photoshop.

Under the hood it uses frame buffer objects and shaders - but the addon handles all of that for you and lets you focus on drawing.

How to get started

If you clone this repo to your addon directory and run the simple example, you will see something like this:

The simple example

The code follows this simple pattern. Just go ahead and draw whatever you like in the layer and the mask:

ofxLayerMask masker;

void ofApp::setup() {
    masker.setup(width, height);
    masker.newLayer();
}

void ofApp::update(){
    //Draw any background here

    masker.beginMask();
    //Draw any mask you like
    masker.endMask();
    
    masker.beginLayer();
    //Draw any layer you like
    masker.endLayer();
}

void ofApp::draw() {
    masker.draw();
}

Working with multiple layers

You can add as many layers as you like. If you run the multi example you will see something like this:

The multi-layer example

The pattern is very similar, with just a couple of differences:

ofxLayerMask masker;
int layer1, layer2;

void ofApp::setup() {
    masker.setup(width, height);
    layer1 = masker.newLayer();
    layer2 = masker.newLayer();
}

void ofApp::update(){
    //Draw any background here

    masker.beginMask(layer1);
    //Draw any mask you like
    masker.endMask(layer1);
    
    masker.beginLayer(layer1);
    //Draw any layer you like
    masker.endLayer(layer1);

    masker.beginMask(layer2);
    //Draw any mask you like
    masker.endMask(layer2);
    
    masker.beginLayer(layer2);
    //Draw any layer you like
    masker.endLayer(layer2);
}

void ofApp::draw() {
    masker.draw();
}

Using the overlay

When you start working with multiple masks and layers it can quickly become confusing without visual feedback. While the examples are running, hit 'o' to get an overlay like this:

The overlay example

To toggle the overlay in your own code, call the toggleOverlay() function:

void ofApp::keyPressed(int key){
    if(key == 'o') {
        masker.toggleOverlay();
    }
}

Dependencies

The addon has no dependencies. Tested against openFrameworks 0.10.1.

ofxlayermask's People

Contributors

microcosm avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.