diff --git a/src/webgl/p5.RendererGL.js b/src/webgl/p5.RendererGL.js index dbcfbca1b4..7f1069bfd5 100644 --- a/src/webgl/p5.RendererGL.js +++ b/src/webgl/p5.RendererGL.js @@ -1125,8 +1125,8 @@ p5.RendererGL = class RendererGL extends p5.Renderer { target.filterCamera._resize(); this._pInst.setCamera(target.filterCamera); this._pInst.resetMatrix(); - this._pInst.image(fbo, -this.width / 2, -this.height / 2, - this.width, this.height); + this._pInst.image(fbo, -target.width / 2, -target.height / 2, + target.width, target.height); this._pInst.pop(); this._pInst.pop(); } diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index c45ebda9a5..0e1b7269e7 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -24,6 +24,52 @@ visualSuite('WebGL', function() { }); }); + visualSuite('filter', function() { + visualTest('On the main canvas', function(p5, screenshot) { + p5.createCanvas(50, 50, p5.WEBGL); + p5.noStroke(); + p5.fill('red'); + p5.circle(0, 0, 20); + p5.filter(p5.GRAY); + screenshot(); + }); + + visualTest('On a framebuffer', function(p5, screenshot) { + p5.createCanvas(50, 50, p5.WEBGL); + const fbo = p5.createFramebuffer({ antialias: true }); + fbo.begin(); + p5.noStroke(); + p5.fill('red'); + p5.circle(0, 0, 20); + p5.filter(p5.GRAY); + fbo.end(); + p5.imageMode(p5.CENTER); + p5.image(fbo, 0, 0); + screenshot(); + }); + + visualTest( + 'On a framebuffer sized differently from the main canvas', + function(p5, screenshot) { + p5.createCanvas(50, 50, p5.WEBGL); + const fbo = p5.createFramebuffer({ + width: 26, + height: 26, + antialias: true + }); + fbo.begin(); + p5.noStroke(); + p5.fill('red'); + p5.circle(0, 0, 20); + p5.filter(p5.GRAY); + fbo.end(); + p5.imageMode(p5.CENTER); + p5.image(fbo, 0, 0); + screenshot(); + } + ); + }); + visualSuite('Lights', function() { visualTest('Fill color and default ambient material', function(p5, screenshot) { p5.createCanvas(50, 50, p5.WEBGL); diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/000.png b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/000.png new file mode 100644 index 0000000000..90ccca1c5d Binary files /dev/null and b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/000.png differ diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/metadata.json b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer sized differently from the main canvas/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/000.png b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/000.png new file mode 100644 index 0000000000..90ccca1c5d Binary files /dev/null and b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/000.png differ diff --git a/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/metadata.json b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/filter/On a framebuffer/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file diff --git a/test/unit/visual/screenshots/WebGL/filter/On the main canvas/000.png b/test/unit/visual/screenshots/WebGL/filter/On the main canvas/000.png new file mode 100644 index 0000000000..176f683c62 Binary files /dev/null and b/test/unit/visual/screenshots/WebGL/filter/On the main canvas/000.png differ diff --git a/test/unit/visual/screenshots/WebGL/filter/On the main canvas/metadata.json b/test/unit/visual/screenshots/WebGL/filter/On the main canvas/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/filter/On the main canvas/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file