Skip to content

Instantly share code, notes, and snippets.

@tado
Last active February 3, 2018 13:22
Show Gist options
  • Save tado/d8f42b1c93540b2c90ac to your computer and use it in GitHub Desktop.
Save tado/d8f42b1c93540b2c90ac to your computer and use it in GitHub Desktop.
Blackmagic capture example
#include "BlackmagicCapture.h"
BlackmagicCapture::BlackmagicCapture(int _width, int _height, float _framerate){
width = _width;
height = _height;
framerate = _framerate;
cam.setup(width, height, framerate);
colorTexture.allocate(width, height, GL_RGB);
fbo.allocate(width, height);
fbo.begin();
ofClear(255, 255, 255, 0);
fbo.end();
}
void BlackmagicCapture::exit() {
cam.close();
}
void BlackmagicCapture::update() {
if(cam.update()) {
colorTexture = cam.getColorTexture();
fbo.begin();
colorTexture.draw(0, 0, width, height/2);
fbo.end();
}
}
void BlackmagicCapture::draw() {
ofPushMatrix();
ofScale(1.0, 2.0);
fbo.draw(0, 0);
ofPopMatrix();
}
#pragma once
#include "ofMain.h"
#include "ofxBlackMagic.h"
class BlackmagicCapture {
public:
BlackmagicCapture(int width, int height, float framerate);
void update();
void draw();
void exit();
int width, height;
float framerate;
ofxBlackMagic cam;
ofTexture colorTexture;
ofFbo fbo;
};
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0);
blackmagic = new BlackmagicCapture(1920, 1080, 60.0);
}
//--------------------------------------------------------------
void ofApp::update(){
blackmagic->update();
}
//--------------------------------------------------------------
void ofApp::draw(){
blackmagic->draw();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}
#pragma once
#include "ofMain.h"
#include "BlackmagicCapture.h"
class ofApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed(int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
BlackmagicCapture * blackmagic;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment