framework2
81 строка · 2.2 Кб
1#include "ofApp.h"2
3void ofApp::setup()4{
5ofBackground(0);6ofSetFrameRate(60);7
8// Setup post-processing chain9post.init(ofGetWidth(), ofGetHeight());10post.createPass<FxaaPass>()->setEnabled(false);11post.createPass<BloomPass>()->setEnabled(false);12post.createPass<DofPass>()->setEnabled(false);13post.createPass<KaleidoscopePass>()->setEnabled(false);14post.createPass<NoiseWarpPass>()->setEnabled(false);15post.createPass<PixelatePass>()->setEnabled(false);16post.createPass<EdgePass>()->setEnabled(false);17post.createPass<VerticalTiltShifPass>()->setEnabled(false);18post.createPass<GodRaysPass>()->setEnabled(false);19
20// Setup box positions21for (unsigned i = 0; i < NUM_BOXES; ++i)22{23posns.push_back(ofVec3f(ofRandom(-300, 300), ofRandom(-300, 300), ofRandom(-300, 300)));24cols.push_back(ofColor::fromHsb(255 * i / (float)NUM_BOXES, 255, 255, 255));25}26
27// Setup light28light.setPosition(1000, 1000, 2000);29
30// create our own box mesh as there is a bug with31// normal scaling and ofDrawBox() at the moment32boxMesh = ofMesh::box(20, 20, 20);33}
34
35void ofApp::update()36{
37ofSetWindowTitle(ofToString(ofGetFrameRate()));38}
39
40void ofApp::draw()41{
42// setup gl state43ofEnableDepthTest();44light.enable();45
46// begin scene to post process47post.begin(cam);48
49// draw boxes50for (unsigned i = 0; i < posns.size(); ++i)51{52ofSetColor(cols[i]);53ofPushMatrix();54ofTranslate(posns[i]);55boxMesh.draw();56ofPopMatrix();57}58
59ofDrawAxis(100);60
61// end scene and draw62post.end();63
64// draw help65ofSetColor(0, 255, 255);66ofDrawBitmapString("Number keys toggle effects, mouse rotates scene", 10, 20);67for (unsigned i = 0; i < post.size(); ++i)68{69if (post[i]->getEnabled()) ofSetColor(0, 255, 255);70else ofSetColor(255, 0, 0);71ostringstream oss;72oss << i << ": " << post[i]->getName() << (post[i]->getEnabled()?" (on)":" (off)");73ofDrawBitmapString(oss.str(), 10, 20 * (i + 2));74}75}
76
77void ofApp::keyPressed(int key)78{
79unsigned idx = key - '0';80if (idx < post.size()) post[idx]->setEnabled(!post[idx]->getEnabled());81}