In this recipe we will show you the way of sharing graphic in real time between applications under Mac OS X. To do that, we will use Syphon and its implementation for Cinder. Syphon is an open source tool that allows an application to share graphics as still frames or real-time updated frame sequence. You can read more about Syphon here: http://syphon.v002.info/
To test if the graphic shared by our application is available, we are going to use Syphon Recorder, which you can find here: http://syphon.v002.info/recorder/
Blocks
.Blocks
group.#include "cinderSyphon.h"
syphonServer mScreenSyphon;
setup
method, add the following code:mScreenSyphon.setName("Cinder Screen"); gl::clear(Color::white());
draw
method add the following code:gl::enableAlphaBlending(); gl::color( ColorA(1.f, 1.f, 1.f, 0.05f) ); gl::drawSolidRect( getWindowBounds() ); gl::color( ColorA::black() ); Vec2f pos = Vec2f( cos(getElapsedSeconds()), sin(getElapsedSeconds())) * 100.f; gl::drawSolidCircle(getWindowCenter() + pos, 10.f); mScreenSyphon.publishScreen();
Application draws a simple rotating animation and shares the whole window area via Syphon library. Our application window looks like the following screenshot:
To test if the graphic can be received by other applications, we will use Syphon Recorder. Run Syphon Recorder and find our Cinder application in the drop-down menu under the name: Cinder Screen – MainApp. We set up the first part of this name at the step 6 of this recipe in the How to do it... section while the second part is an executable file name. Now, the preview from our Cinder application should be available and it would looks like the following screenshot:
The Syphon library is very useful, simple to use, and is available for other applications and libraries.
You can receive textures from other applications as well. To do this, you have to use the syphonClient
class as shown in the following steps:
syphonClient mClientSyphon;
mClientSyphon
inside the CIT method:mClientSyphon.setApplicationName("MainApp Server"); mClientSyphon.setServerName(""); mClientSyphon.bind();
draw
method add the following line which draws graphics that the other application is sharing:mClientSyphon.draw(Vec2f::zero());
3.139.86.18