-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofApp.cpp
55 lines (42 loc) · 1.52 KB
/
ofApp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetWindowTitle("openframeworks");
this->cap.open(1);
this->cap_size = cv::Size(1280, 720);
this->image.allocate(this->cap_size.width, this->cap_size.height, OF_IMAGE_COLOR);
this->frame = cv::Mat(cv::Size(this->image.getWidth(), this->image.getHeight()), CV_MAKETYPE(CV_8UC3, this->image.getPixels().getNumChannels()), this->image.getPixels().getData(), 0);
this->shader.load("shader/shader.vert", "shader/shader.frag");
}
//--------------------------------------------------------------
void ofApp::update() {
cv::Mat src;
this->cap >> src;
if (src.empty()) {
// If capture source is video
this->cap.set(CV_CAP_PROP_POS_FRAMES, 1);
return;
}
cv::resize(src, this->frame, this->cap_size);
cv::cvtColor(this->frame, this->frame, CV_BGR2RGB);
cv::flip(this->frame, this->frame, 2);
this->image.update();
}
//--------------------------------------------------------------
void ofApp::draw() {
this->shader.begin();
this->shader.setUniform1f("time", ofGetElapsedTimef());
this->shader.setUniform2f("resolution", ofGetWidth(), ofGetHeight());
this->shader.setUniformTexture("tex", this->image, 1);
ofDrawRectangle(0, 0, ofGetWidth(), ofGetHeight());
this->shader.end();
}
//--------------------------------------------------------------
int main() {
ofGLWindowSettings settings;
settings.setGLVersion(3, 2);
settings.setSize(1280, 720);
ofCreateWindow(settings);
ofRunApp(new ofApp());
}