From 117418337aae49cf42eb025a2bc1669b2f012e92 Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Wed, 8 May 2019 18:19:15 +0200 Subject: [PATCH 1/2] Make automatic gui for all used effects --- example/example.qbs | 3 +- example/src/ofApp.cpp | 95 +++++++++++++++++++++++++++---------------- example/src/ofApp.h | 12 +++++- 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/example/example.qbs b/example/example.qbs index 92d4212..8638a28 100644 --- a/example/example.qbs +++ b/example/example.qbs @@ -15,12 +15,11 @@ Project{ 'src/main.cpp', 'src/ofApp.cpp', 'src/ofApp.h', - 'src/testApp.cpp', - 'src/testApp.h', ] of.addons: [ 'ofxPostProcessing', + 'ofxGui' ] // additional flags for the project. the of module sets some diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index 9fb11fc..45e775b 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -7,29 +7,61 @@ void ofApp::setup() // Setup post-processing chain post.init(ofGetWidth(), ofGetHeight()); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - post.createPass()->setEnabled(false); - + + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + //post.createPass(); // use of undeclared identifier 'HsbShiftPass' + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + post.createPass(); + + gui.setup("panel"); + gui.add(spread.set("spread", 100.0f, 50.0f, 300.0f)); + gui.add(scale.set("scale", 20.0f, 20.0f, 200.0f)); + + for(auto & pass : post.getPasses()) { + pass->setEnabled(false); + ofParameter param; + gui.add(param.set(pass->getName(), false)); + param.addListener(this, &ofApp::toggleListener); + passes[pass->getName()] = pass; + } + // Setup box positions - for (unsigned i = 0; i < NUM_BOXES; ++i) - { - posns.push_back(ofVec3f(ofRandom(-300, 300), ofRandom(-300, 300), ofRandom(-300, 300))); - cols.push_back(ofColor::fromHsb(255 * i / (float)NUM_BOXES, 255, 255, 255)); + for (unsigned i = 0; i < NUM_BOXES; ++i) { + posns.push_back(ofVec3f(ofRandomf(), ofRandomf(), ofRandomf())); + cols.push_back(ofColor::fromHsb(i * 255.0f / NUM_BOXES, 255, ofRandom(255), 255)); } // Setup light light.setPosition(1000, 1000, 2000); - + light.enable(); + // create our own box mesh as there is a bug with // normal scaling and ofDrawBox() at the moment - boxMesh = ofMesh::box(20, 20, 20); + boxMesh = ofMesh::box(1, 1, 1); +} + +void ofApp::toggleListener(const void * sender, bool & value) { + auto name = ((const ofParameter*) sender)->getName(); + passes[name]->setEnabled(value); } void ofApp::update() @@ -41,8 +73,8 @@ void ofApp::draw() { // setup gl state ofEnableDepthTest(); - light.enable(); - + ofEnableLighting(); + // begin scene to post process post.begin(cam); @@ -51,7 +83,10 @@ void ofApp::draw() { ofSetColor(cols[i]); ofPushMatrix(); - ofTranslate(posns[i]); + ofTranslate(posns[i] * spread); + ofRotateXRad(i); + ofRotateYRad(i*3); + ofScale(scale); boxMesh.draw(); ofPopMatrix(); } @@ -61,21 +96,9 @@ void ofApp::draw() // end scene and draw post.end(); - // draw help - ofSetColor(0, 255, 255); - ofDrawBitmapString("Number keys toggle effects, mouse rotates scene", 10, 20); - for (unsigned i = 0; i < post.size(); ++i) - { - if (post[i]->getEnabled()) ofSetColor(0, 255, 255); - else ofSetColor(255, 0, 0); - ostringstream oss; - oss << i << ": " << post[i]->getName() << (post[i]->getEnabled()?" (on)":" (off)"); - ofDrawBitmapString(oss.str(), 10, 20 * (i + 2)); - } -} + ofDisableDepthTest(); + ofDisableLighting(); -void ofApp::keyPressed(int key) -{ - unsigned idx = key - '0'; - if (idx < post.size()) post[idx]->setEnabled(!post[idx]->getEnabled()); -} \ No newline at end of file + ofSetColor(ofColor::white); + gui.draw(); +} diff --git a/example/src/ofApp.h b/example/src/ofApp.h index 89f1afd..d4ad3d1 100644 --- a/example/src/ofApp.h +++ b/example/src/ofApp.h @@ -2,6 +2,7 @@ #include "ofMain.h" #include "ofxPostProcessing.h" +#include "ofxGui.h" class ofApp : public ofBaseApp { @@ -12,8 +13,6 @@ class ofApp : public ofBaseApp void update(); void draw(); - void keyPressed(int key); - // scene stuff ofxPostProcessing post; ofEasyCam cam; @@ -23,4 +22,13 @@ class ofApp : public ofBaseApp vector posns; vector cols; ofVboMesh boxMesh; + + ofParameter spread; + ofParameter scale; + + std::map passes; + + ofxPanel gui; + + void toggleListener(const void * sender, bool & value); }; From 58971e40481e0557d56321526623a0507627af59 Mon Sep 17 00:00:00 2001 From: Abe Pazos Date: Wed, 8 May 2019 18:23:19 +0200 Subject: [PATCH 2/2] Add ofxGui to addons.make --- example/addons.make | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/addons.make b/example/addons.make index 5c7f954..d58fc69 100644 --- a/example/addons.make +++ b/example/addons.make @@ -1 +1,3 @@ ofxPostProcessing +ofxGui +