diff --git a/example-Basic/src/ofApp.cpp b/example-Basic/src/ofApp.cpp index b877694..7bef557 100644 --- a/example-Basic/src/ofApp.cpp +++ b/example-Basic/src/ofApp.cpp @@ -16,6 +16,7 @@ void ofApp::setup(){ mainOutputSyphonServer.setName("Screen Output"); individualTextureSyphonServer.setName("Texture Output"); + bindedTextureSyphonServer.setName("binded Texture Output"); mClient.setup(); @@ -34,7 +35,8 @@ void ofApp::update(){ //-------------------------------------------------------------- void ofApp::draw(){ - + + if(bindedTextureSyphonServer.tryToBindForSize(800, 600)){ // Clear with alpha, so we can capture via syphon and composite elsewhere should we want. glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -121,10 +123,22 @@ void ofApp::draw(){ mClient.draw(50, 50); - mainOutputSyphonServer.publishScreen(); - - individualTextureSyphonServer.publishTexture(&tex); - + + + + bindedTextureSyphonServer.unbindAndPublish(); + } + + + + individualTextureSyphonServer.publishTexture(&tex); + + + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + bindedTextureSyphonServer.getCurrentTexture().draw(0,0); + mainOutputSyphonServer.publishScreen(); + ofDrawBitmapString("Note this text is not captured by Syphon since it is drawn after publishing.\nYou can use this to hide your GUI for example.", 150,500); } diff --git a/example-Basic/src/ofApp.h b/example-Basic/src/ofApp.h index 9010534..ebcd1f4 100644 --- a/example-Basic/src/ofApp.h +++ b/example-Basic/src/ofApp.h @@ -22,6 +22,7 @@ class ofApp : public ofBaseApp{ ofxSyphonServer mainOutputSyphonServer; ofxSyphonServer individualTextureSyphonServer; + ofxSyphonServer bindedTextureSyphonServer; ofxSyphonClient mClient; }; diff --git a/src/ofxSyphonServer.h b/src/ofxSyphonServer.h index bca62a0..6c5467a 100644 --- a/src/ofxSyphonServer.h +++ b/src/ofxSyphonServer.h @@ -10,14 +10,19 @@ #include "ofMain.h" class ofxSyphonServer { - public: +public: ofxSyphonServer(); ~ofxSyphonServer(); void setName (string n); string getName(); void publishScreen(); - void publishTexture(ofTexture* inputTexture); - void publishTexture(GLuint id, GLenum target, GLsizei width, GLsizei height, bool isFlipped); - protected: + void publishTexture(ofTexture* inputTexture); + void publishTexture(GLuint id, GLenum target, GLsizei width, GLsizei height, bool isFlipped); + bool tryToBindForSize(int w,int h); + void unbindAndPublish(); + ofTexture & getCurrentTexture(); + void updateCurrentTexture(); +protected: + ofTexture mTex; void *mSyphon; }; diff --git a/src/ofxSyphonServer.mm b/src/ofxSyphonServer.mm index b94af98..bfe8a9d 100644 --- a/src/ofxSyphonServer.mm +++ b/src/ofxSyphonServer.mm @@ -114,4 +114,70 @@ [(SyphonServer *)mSyphon publishFrameTexture:id textureTarget:target imageRegion:NSMakeRect(0, 0, width, height) textureDimensions:NSMakeSize(width, height) flipped:!isFlipped]; [pool drain]; -} \ No newline at end of file +} + +bool ofxSyphonServer::tryToBindForSize(int w,int h){ + bool res; + @autoreleasepool{ + + if (!mSyphon) + { + mSyphon = [[SyphonServer alloc] initWithName:@"Untitled" context:CGLGetCurrentContext() options:nil]; + } + + res = [(SyphonServer *)mSyphon bindToDrawFrameOfSize:NSMakeSize( w,h)]; + if(res){ + ofPushMatrix(); + ofPushView(); + ofViewport(0,0,w,h,false); + ofSetupScreenOrtho(w,h); + + } + } + + return res; +} + +void ofxSyphonServer::unbindAndPublish(){ + if (mSyphon){ + @autoreleasepool{ + [(SyphonServer *)mSyphon unbindAndPublish]; + + updateCurrentTexture(); + ofPopView(); + ofPopMatrix(); + } + } +} + +ofTexture & ofxSyphonServer::getCurrentTexture(){ + return mTex; +} +void ofxSyphonServer::updateCurrentTexture(){ + + if(!mSyphon) return ; + @autoreleasepool{ + SyphonImage * Img =[(SyphonServer *)mSyphon newFrameImage] ; + NSSize texSize = [(SyphonImage*)Img textureSize]; + mTex.setUseExternalTextureID([Img textureName]); + + + mTex.texData.textureTarget = GL_TEXTURE_RECTANGLE_ARB; // Syphon always outputs rect textures. + mTex.texData.width = texSize.width; + mTex.texData.height = texSize.height; + mTex.texData.tex_w = texSize.width; + mTex.texData.tex_h = texSize.height; + mTex.texData.tex_t = texSize.width; + mTex.texData.tex_u = texSize.height; + mTex.texData.glInternalFormat = GL_RGBA; +#if (OF_VERSION_MAJOR == 0) && (OF_VERSION_MINOR < 8) + mTex.texData.glType = GL_RGBA; + mTex.texData.pixelType = GL_UNSIGNED_BYTE; +#endif + mTex.texData.bFlipTexture = YES; + mTex.texData.bAllocated = YES; + + + } + +}