Sharing graphics between applications

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/

Getting ready

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/

How to do it…

  1. Checkout Syphon CinderBlock from the syphon-implementations repository http://code.google.com/p/syphon-implementations/.
  2. Create a new group inside your project tree and name it Blocks.
  3. Drag-and-drop Syphon CinderBlock into your newly created Blocks group.
    How to do it…
  4. Make sure Syphon.framework is added to the Copy Files section of Build Phases in the target settings.
  5. Add necessary header files:
    #include "cinderSyphon.h"
  6. Add property to your main application class:
    syphonServer mScreenSyphon;
  7. At the end of setup method, add the following code:
    mScreenSyphon.setName("Cinder Screen");
    gl::clear(Color::white());
  8. Inside the 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();

How it works…

Application draws a simple rotating animation and shares the whole window area via Syphon library. Our application window looks like the following screenshot:

How it works…

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:

How it works…

There's more...

The Syphon library is very useful, simple to use, and is available for other applications and libraries.

Receiving graphics from other applications

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:

  1. Add a property to your application main class:
    syphonClient mClientSyphon;
  2. Initialize mClientSyphon inside the CIT method:
    mClientSyphon.setApplicationName("MainApp Server");
    mClientSyphon.setServerName("");
    mClientSyphon.bind();
  3. At the end of the draw method add the following line which draws graphics that the other application is sharing:
    mClientSyphon.draw(Vec2f::zero());
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.86.18