framework2

Форк
0
81 строка · 2.2 Кб
1
#include "ofApp.h"
2

3
void ofApp::setup()
4
{
5
    ofBackground(0);
6
    ofSetFrameRate(60);
7
    
8
    // Setup post-processing chain
9
    post.init(ofGetWidth(), ofGetHeight());
10
    post.createPass<FxaaPass>()->setEnabled(false);
11
    post.createPass<BloomPass>()->setEnabled(false);
12
    post.createPass<DofPass>()->setEnabled(false);
13
    post.createPass<KaleidoscopePass>()->setEnabled(false);
14
    post.createPass<NoiseWarpPass>()->setEnabled(false);
15
    post.createPass<PixelatePass>()->setEnabled(false);
16
    post.createPass<EdgePass>()->setEnabled(false);
17
    post.createPass<VerticalTiltShifPass>()->setEnabled(false);
18
    post.createPass<GodRaysPass>()->setEnabled(false);
19
    
20
    // Setup box positions
21
    for (unsigned i = 0; i < NUM_BOXES; ++i)
22
    {
23
        posns.push_back(ofVec3f(ofRandom(-300, 300), ofRandom(-300, 300), ofRandom(-300, 300)));
24
        cols.push_back(ofColor::fromHsb(255 * i / (float)NUM_BOXES, 255, 255, 255));
25
    }
26
    
27
    // Setup light
28
	light.setPosition(1000, 1000, 2000);
29
    
30
    // create our own box mesh as there is a bug with
31
    // normal scaling and ofDrawBox() at the moment
32
    boxMesh = ofMesh::box(20, 20, 20);
33
}
34

35
void ofApp::update()
36
{
37
    ofSetWindowTitle(ofToString(ofGetFrameRate()));
38
}
39

40
void ofApp::draw()
41
{
42
    // setup gl state
43
    ofEnableDepthTest();
44
    light.enable();
45
    
46
    // begin scene to post process
47
    post.begin(cam);
48
    
49
    // draw boxes
50
    for (unsigned i = 0; i < posns.size(); ++i)
51
    {
52
        ofSetColor(cols[i]);
53
        ofPushMatrix();
54
        ofTranslate(posns[i]);
55
        boxMesh.draw();
56
        ofPopMatrix();
57
    }
58
    
59
    ofDrawAxis(100);
60
    
61
    // end scene and draw
62
    post.end();
63
    
64
    // draw help
65
    ofSetColor(0, 255, 255);
66
    ofDrawBitmapString("Number keys toggle effects, mouse rotates scene", 10, 20);
67
    for (unsigned i = 0; i < post.size(); ++i)
68
    {
69
        if (post[i]->getEnabled()) ofSetColor(0, 255, 255);
70
        else ofSetColor(255, 0, 0);
71
        ostringstream oss;
72
        oss << i << ": " << post[i]->getName() << (post[i]->getEnabled()?" (on)":" (off)");
73
        ofDrawBitmapString(oss.str(), 10, 20 * (i + 2));
74
    }
75
}
76

77
void ofApp::keyPressed(int key)
78
{
79
    unsigned idx = key - '0';
80
    if (idx < post.size()) post[idx]->setEnabled(!post[idx]->getEnabled());
81
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.