Skip to content

Commit

Permalink
Make Framebuffer match alpha settings of the parent context
Browse files Browse the repository at this point in the history
  • Loading branch information
davepagurek committed Mar 20, 2022
1 parent 6d23ca6 commit 33e64df
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/simple/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html><html lang="en"><head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js"></script>
<script src="../../p5.Framebuffer.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8">
Expand Down
4 changes: 3 additions & 1 deletion examples/simple/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function draw() {
// Draw a sphere to the Framebuffer
fbo.draw(() => {
clear()
background(255)
push()
noStroke()
fill(255, 0, 0)
Expand All @@ -20,6 +21,7 @@ function draw() {

// Do something with fbo.color or dbo.depth
clear()
background(255)
push()
noStroke()

Expand All @@ -36,4 +38,4 @@ function draw() {
pop()

pop()
}
}
5 changes: 3 additions & 2 deletions p5.Framebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
)
Expand Down

0 comments on commit 33e64df

Please sign in to comment.