【OF】OF + Syphon

環境は、OF 0.8.4、XCode 6.1.1

 

・ofxSyphonをgit clone.

・pgでサンプルスケルトン作成。

 ofxSyphonをaddonで追加

 

・プロジェクトを開いて、下記設定する

スクリーンショット 2014-12-21 午後11.10.21

・テストコード (ofApp.h)

#include "ofMain.h"
#include "ofxSyphon.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);
		
    ofSoundPlayer mySound;
    float radius;
    
    ofxSyphonServer mainOutputSyphonServer;
    ofxSyphonServer individualTextureSyphonServer;
    ofxSyphonClient mClient;
};

 

ofApp.m

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){

    ofBackground(0, 0, 0);
    ofSetVerticalSync(true);
    ofSetCircleResolution(64);
    ofEnableAlphaBlending();
    
    ofSetFrameRate(60);
    ofSetBackgroundAuto(false);
//    ofSetFullscreen(true);

    
    //SYPHON
    mainOutputSyphonServer.setName("Screen Outputh");
    mClient.setup();
    mClient.setApplicationName("Simple Serverh");
    mClient.setServerName("");
    
}

//--------------------------------------------------------------
void ofApp::update(){
}

//--------------------------------------------------------------
void ofApp::draw(){

    ofSetColor(0, 0, 0, 5);
    ofRect(0, 0, ofGetWindowWidth(), ofGetWindowHeight());

    
    int radius = ofRandom(10, 50);

    int r = ofRandom(100, 255);
    int g = ofRandom(255, 255);
    int b = ofRandom(255, 255);
    
    ofSetColor(r, g, b);

    int x = ofRandom(0, ofGetWindowWidth());
    int y = ofRandom(0, ofGetWindowHeight());
    
    ofCircle(x, y, radius);

    //SYPHON
    mClient.draw(50, 50);
    mainOutputSyphonServer.publishScreen();
}

 

mad mapperで連携できます。

 

 

【OF】mbp retina

MacでRetina displayに対応する。

 

・openFrameworks-Info.plistを開く

・Add Rowで、High Resolution Capableを”YES” 追加

 

【main.cpp】

ofSetupOpenGL(1920, 1920, OF_WINDOW); // <——– setup the GL context

ofSetWindowShape(1920,1920);

    

 

 

【OF/iOS】Customize AppDelegate.

・Viewを重ねる方法

・OFのViewの背景を透過する。

    ofxiOSSetGLViewTransparent(true);

 

main.m

#include "ofMain.h"
#include "ofApp.h"

int main(){
    
    ofAppiOSWindow * window = new ofAppiOSWindow();
    window->enableRetina();
    
    ofSetupOpenGL(ofPtr<ofAppBaseWindow>(window), 1024,768, OF_FULLSCREEN);
    window->startAppWithDelegate("MyAppDelegate");
}

 

MyAppDelegate.mm

#import "MyAppDelegate.h"

@implementation MyAppDelegate

@synthesize vc;
AVCaptureVideoPreviewLayer* previewLayer;
UIView* cameraView;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    [super applicationDidFinishLaunching:application];
    
    self.vc = [[RootViewController alloc] init];
    [self.window setRootViewController: self.vc];
    
    setupCameraPreview();
    [self.vc.view addSubview: cameraView];

    AppViewController* app = [[AppViewController alloc] init];
    [self.vc.view addSubview: app.view];

    
    return YES;
}

- (void) dealloc {
    self.vc = nil;
    [super dealloc];
}



void setupCameraPreview()
{
    AVCaptureSession *session = [AVCaptureSession new];
//    [session setSessionPreset:AVCaptureSessionPreset1920x1080];
    [session setSessionPreset:AVCaptureSessionPreset1280x720];
    
    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
    
    if ([session canAddInput:deviceInput]){
        [session addInput:deviceInput];
    }
    
    previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    [previewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
    [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    
    cameraView = [[UIView alloc]initWithFrame: CGRectMake(0,0,640/2,1136/2)];
    cameraView.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.f];
    
    CALayer *rootLayer = [cameraView layer];
    [rootLayer setMasksToBounds:YES];
    [previewLayer setFrame:[rootLayer bounds]];
    [rootLayer addSublayer:previewLayer];
    [session startRunning];
   
}
@end

 

MyAppDelegate.h

#import "ofxiOSAppDelegate.h"

#import <AVFoundation/AVFoundation.h>
#import "AppViewController.h"
#import "RootViewController.h"

@interface MyAppDelegate : ofxiOSAppDelegate {

}

@property (nonatomic, retain) RootViewController* vc;

 

RootViewController.h

@interface RootViewController : UIViewController

@end

 

RootViewController.mm

#import <Foundation/Foundation.h>
#import "RootViewController.h"

@implementation RootViewController

- (BOOL)shouldAutorotate {

    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeRight;
}
@end

 

AppViewController.mm

#import "AppViewController.h"
#import "ofApp.h"

@implementation AppViewController

- (id)init {

   self = [super initWithFrame:[UIScreen mainScreen].bounds app: new ofApp()];
    if(self != nil) {

    }
    return self;
}

@end

 

AppViewController.h

#import "ofxiOSViewController.h"

@interface AppViewController : ofxiOSViewController

@end

ofApp.mm

//--------------------------------------------------------------
void ofApp::setup(){
 
    ofBackground(0,0,0,0);
    ofSetOrientation(OF_ORIENTATION_DEFAULT);
    
    ofxiOSSendGLViewToFront();
    ofxiOSSetGLViewTransparent(true);
//    ofxiOSSetGLViewUserInteraction(false);
    
    ofEnableAlphaBlending();
    camera.setPosition(0,0,0);
    camera.setupPerspective();
    camera.setVFlip(false);
    camera.setFarClip(5000);
    //camera.disableMouseInput();
}


//--------------------------------------------------------------
void ofApp::update() {
}

//--------------------------------------------------------------
void ofApp::draw() {

    camera.begin();

    ofSetColor(255, 0, 0,100);
    ofSetConeResolution(32, 16);
    ofDrawCone(0, 0, 0, 25, 50);

    camera.end();
}

//--------------------------------------------------------------
void ofApp::exit(){
    
}

ofApp.h

class ofApp : public ofxiOSApp {

    public:
        void setup();
        void update();
        void draw();
        void exit();
	
        void touchDown(ofTouchEventArgs & touch);
        void touchMoved(ofTouchEventArgs & touch);
        void touchUp(ofTouchEventArgs & touch);
        void touchDoubleTap(ofTouchEventArgs & touch);
        void touchCancelled(ofTouchEventArgs & touch);

}