Applying a shader to a PGraphics object via filter()

edited June 2016 in GLSL / Shaders

I'm trying to apply multiple shaders independently to separate parts of a sketch using PGraphics objects. The following code (in v3.x) illustrates what I'm trying to do.

PShader blur;
PGraphics PG;

void setup(){
  size(500,500,P2D);
  blur = loadShader("blur.glsl");
  PG = createGraphics(width,height);
}

void draw(){
  background(50);

  PG.beginDraw();
  PG.noStroke();
  PG.fill(205);
  PG.rect(100,100,300,300);
  PG.filter(blur);
  PG.endDraw();
  image(PG,0,0);
}

(blur.glsl is a copy of the ShaderBlur example code)

Running the code returns the following error:

filter(), or this particular variation of it, is not available with this renderer.

It appears as though this functionality was once possible, per this thread: How to use a fragment shader on a PGraphics in Processing 2.0xx?

Is this because the shader can only be applied to the main output? Or is this just a limitation of the renderer I'm using? Any guidance is much appreciated.

Answers

  • Don't you need to do PG = createGraphics(width, height, P2D); ?(missing P2D)

Sign In or Register to comment.