Syphon / Processing

Syphon Implementation for Processing
Other
137 stars 33 forks source link

Possible issue using filter() inside of PGraphics for Syphon in Processing? #41

Open CaseyJScalf opened 2 years ago

CaseyJScalf commented 2 years ago

MacBook Pro Retina Mid-2015 OSX 11.5.1 Processing 3.5.4

I am using the Syphon Processing library and I have found a possible issue when it comes to using the filter() function inside of the PGraphics canvas for sending out frames via a Syphon Server.

I have noted that the filters used, BLUR & INVERT, do appear correctly in the Processing window however they do not appear to be sent out correctly in the Syphon output.

Is there a reason for this?

Possible solution or fix?

Or, should I try to apply the filters in a different manner altogether?

Thank you for any tips or help!

Please see code and screenshot below:

import codeanticode.syphon.*;

PGraphics canvas;
SyphonServer server;

void setup() { 
  size(400,400, P3D);
  canvas = createGraphics(400, 400, P3D);
  frameRate(30);

  // Create syhpon server to send frames out.
  server = new SyphonServer(this, "Processing Syphon");
}

void draw() {
  canvas.beginDraw();
  canvas.background(127);
  canvas.lights();
  canvas.translate(width/2, height/2);
  canvas.rotateX(frameCount * 0.01);
  canvas.rotateY(frameCount * 0.01);  
  canvas.box(150);
  canvas.filter(INVERT);
  canvas.filter(BLUR, 3);
  canvas.endDraw();
  image(canvas, 0, 0);
  server.sendImage(canvas);
}

Screen Shot 2022-01-28 at 3 19 44 PM

codeanticode commented 2 years ago

It's actually the same as #32, since mask() just calls filter(). I think it's an upstream bug in the OpenGL renderer in Processing.

CaseyJScalf commented 2 years ago

Nice work I appreciate the follow up. I took a look at #32 and found that to be a helpful description of the problem with the ordering of the "server.sendImage(canvas);" in the beginning being rather helpful.

I did notice that if I put it at the very start the Syphon output was good but the Processing window would be null. So I put it just after beginDraw()

The code below works great now and is shown in the screenshot.

Screen Shot 2022-03-13 at 3 25 19 PM

import codeanticode.syphon.*;

PGraphics canvas;
SyphonServer server;

void setup() { 
  size(400,400, P3D);
  canvas = createGraphics(400, 400, P3D);
  frameRate(30);

  // Create syhpon server to send frames out.
  server = new SyphonServer(this, "Processing Syphon");
}

void draw() {

  canvas.beginDraw();

  server.sendImage(canvas);

  canvas.background(127);
  canvas.lights();
  canvas.translate(width/2, height/2);
  canvas.rotateX(frameCount * 0.01);
  canvas.rotateY(frameCount * 0.01);  
  canvas.box(150);
  canvas.filter(INVERT);
  canvas.filter(BLUR, 3);
  canvas.endDraw();
  image(canvas, 0, 0);

}