From 33e64df0b6d90afae1dec0af26e4c0345f90cb26 Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Sun, 20 Mar 2022 08:40:13 -0400 Subject: [PATCH] Make Framebuffer match alpha settings of the parent context --- examples/simple/index.html | 2 +- examples/simple/sketch.js | 4 +++- p5.Framebuffer.js | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/simple/index.html b/examples/simple/index.html index 2d35edd..5ad27e5 100644 --- a/examples/simple/index.html +++ b/examples/simple/index.html @@ -1,5 +1,5 @@ - + diff --git a/examples/simple/sketch.js b/examples/simple/sketch.js index 5c3f84b..ab99326 100644 --- a/examples/simple/sketch.js +++ b/examples/simple/sketch.js @@ -9,6 +9,7 @@ function draw() { // Draw a sphere to the Framebuffer fbo.draw(() => { clear() + background(255) push() noStroke() fill(255, 0, 0) @@ -20,6 +21,7 @@ function draw() { // Do something with fbo.color or dbo.depth clear() + background(255) push() noStroke() @@ -36,4 +38,4 @@ function draw() { pop() pop() -} \ No newline at end of file +} diff --git a/p5.Framebuffer.js b/p5.Framebuffer.js index 0f0e224..ea7925b 100644 --- a/p5.Framebuffer.js +++ b/p5.Framebuffer.js @@ -97,6 +97,7 @@ class Framebuffer { const width = this._renderer.width const height = this._renderer.height const density = this._renderer._pInst._pixelDensity + const hasAlpha = this._renderer._pInst._glAttributes.alpha const colorTexture = gl.createTexture() if (!colorTexture) { @@ -111,11 +112,11 @@ class Framebuffer { gl.texImage2D( gl.TEXTURE_2D, 0, - gl.RGBA, + hasAlpha ? gl.RGBA : gl.RGB, width * density, height * density, 0, - gl.RGBA, + hasAlpha ? gl.RGBA : gl.RGB, gl.UNSIGNED_BYTE, null, )