Hello,
I've managed to plug Processing into MadMapper and other syphon enabled software quite easily using the JSyphon libs in both plain old java and in Processing. Just go to
http://code.google.com/p/syphon-implementations/source/browse/#svn%2Ftrunk%2FSyphon%20Implementations%2FProcessing download the library and put it into Processing Library folder. It works like a treat for me, I've done a couple of small projects using it now, and am in the process of writing some simple apps like the Mad Labs ones but in Processing.
There is two methods of using it:
- either you can use the method shown in the examples
- or another method is to use the GLGraphics library to create an GLOffscreenBuffer, draw everything to the offscreen buffer then publish the offscreen buffer as a GLTexture to the Syphon server - Code example below.
Code: Select all
/*Processing to MadMapper, Modul8 and VDMX etc, using Syphon to output*/
import codeanticode.glgraphics.*;
import javax.media.opengl.*;
import processing.opengl.*;
import jsyphon.*;
JSyphonServer syphon; // syphon
GLGraphicsOffScreen outputCanvas; // offscreen buffer
GLTexture outTex; // output texture
int outW = 1024; // offscreen buffer width
int outH = 768; // offscreen buffer height
void setup() {
size(1024, 768, GLConstants.GLGRAPHICS);
background(0);
smooth();
frameRate(30);
// setup the offscreen buffers
outputCanvas = new GLGraphicsOffScreen(this, outW, outH, true, 4);
// create the gl texture that will be sent to syphon
outTex = new GLTexture(this);
// init syphon
initSyphon(outputCanvas.gl);
}
void draw() {
// clear the background of the screen
background(0, 0, 0);
// draw to the offscreen buffer
outputCanvas.beginDraw();
// removed the clear for the desired drawing effect - should be included - acts like background(###);
//canvas.clear(0, 0, 0, 0);
outputCanvas.fill(0, 4);
outputCanvas.noStroke();
outputCanvas.rect(0, 0, width, height);
if (frameCount%5==0) {
outputCanvas.stroke(random(130, 170), random(220, 255), random(130));
branch(outputCanvas, random(0, width), height, height-(random(120, height-50)), radians(270));
}
outputCanvas.endDraw();
// retrieve the offscreen buffer
outTex = outputCanvas.getTexture();
// display offscreen buffer to the screen
image(outTex, 0, 0);
// publish the offscreen buffer to syphon
syphon.publishFrameTexture(outTex.getTextureID(), outTex.getTextureTarget(), 0, 0, outTex.width, outTex.height, outTex.width, outTex.height, true);
}
// draw a recursive tree routine
void branch(GLGraphicsOffScreen c, float x, float y, float s, float a) {
c.strokeWeight(s*0.04);
a+=radians(random(-7, 7));
float newx = x+cos(a)*s;
float newy = y+sin(a)*s;
c.line(x, y, newx, newy);
if (s>3) {
branch(c, newx, newy, s*(random(0.55, 0.70)), a-radians(random(17, 12)));
branch(c, newx, newy, s*(random(0.55, 0.70)), a+radians(random(17, 12)));
}
}
// init syphon
void initSyphon(GL gl) {
if (syphon != null) {
syphon.stop();
}
syphon = new JSyphonServer();
//syphon.test();
syphon.initWithName("Processing_OffscreenTest");
}
Hope this helps