Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/addons.make
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ofxPostProcessing
ofxGui

3 changes: 1 addition & 2 deletions example/example.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 59 additions & 36 deletions example/src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,61 @@ void ofApp::setup()

// Setup post-processing chain
post.init(ofGetWidth(), ofGetHeight());
post.createPass<FxaaPass>()->setEnabled(false);
post.createPass<BloomPass>()->setEnabled(false);
post.createPass<DofPass>()->setEnabled(false);
post.createPass<KaleidoscopePass>()->setEnabled(false);
post.createPass<NoiseWarpPass>()->setEnabled(false);
post.createPass<PixelatePass>()->setEnabled(false);
post.createPass<EdgePass>()->setEnabled(false);
post.createPass<VerticalTiltShifPass>()->setEnabled(false);
post.createPass<GodRaysPass>()->setEnabled(false);


post.createPass<BleachBypassPass>();
post.createPass<BloomPass>();
post.createPass<ContrastPass>();
post.createPass<ConvolutionPass>();
post.createPass<DofAltPass>();
post.createPass<DofPass>();
post.createPass<EdgePass>();
post.createPass<FakeSSSPass>();
post.createPass<FxaaPass>();
post.createPass<GodRaysPass>();
post.createPass<HorizontalTiltShifPass>();
//post.createPass<HsbShiftPass>(); // use of undeclared identifier 'HsbShiftPass'
post.createPass<KaleidoscopePass>();
post.createPass<LimbDarkeningPass>();
post.createPass<LUTPass>();
post.createPass<NoiseWarpPass>();
post.createPass<PixelatePass>();
post.createPass<RGBShiftPass>();
post.createPass<RimHighlightingPass>();
post.createPass<SSAOPass>();
post.createPass<ToonPass>();
post.createPass<VerticalTiltShifPass>();
post.createPass<ZoomBlurPass>();

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<bool> 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<bool>*) sender)->getName();
passes[name]->setEnabled(value);
}

void ofApp::update()
Expand All @@ -41,8 +73,8 @@ void ofApp::draw()
{
// setup gl state
ofEnableDepthTest();
light.enable();
ofEnableLighting();

// begin scene to post process
post.begin(cam);

Expand All @@ -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();
}
Expand All @@ -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());
}
ofSetColor(ofColor::white);
gui.draw();
}
12 changes: 10 additions & 2 deletions example/src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ofMain.h"
#include "ofxPostProcessing.h"
#include "ofxGui.h"

class ofApp : public ofBaseApp
{
Expand All @@ -12,8 +13,6 @@ class ofApp : public ofBaseApp
void update();
void draw();

void keyPressed(int key);

// scene stuff
ofxPostProcessing post;
ofEasyCam cam;
Expand All @@ -23,4 +22,13 @@ class ofApp : public ofBaseApp
vector<ofVec3f> posns;
vector<ofColor> cols;
ofVboMesh boxMesh;

ofParameter<float> spread;
ofParameter<float> scale;

std::map<std::string, RenderPass::Ptr> passes;

ofxPanel gui;

void toggleListener(const void * sender, bool & value);
};