Skip to content

Commit c45c5b5

Browse files
authored
Merge pull request #6 from davepagurek/fix/p51.4.1
Make Framebuffer match alpha settings of the parent context
2 parents 6d23ca6 + 33e64df commit c45c5b5

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

examples/simple/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html><html lang="en"><head>
2-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>
2+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.1/p5.min.js"></script>
33
<script src="../../p5.Framebuffer.js" type="text/javascript"></script>
44
<link rel="stylesheet" type="text/css" href="style.css">
55
<meta charset="utf-8">

examples/simple/sketch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function draw() {
99
// Draw a sphere to the Framebuffer
1010
fbo.draw(() => {
1111
clear()
12+
background(255)
1213
push()
1314
noStroke()
1415
fill(255, 0, 0)
@@ -20,6 +21,7 @@ function draw() {
2021

2122
// Do something with fbo.color or dbo.depth
2223
clear()
24+
background(255)
2325
push()
2426
noStroke()
2527

@@ -36,4 +38,4 @@ function draw() {
3638
pop()
3739

3840
pop()
39-
}
41+
}

p5.Framebuffer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Framebuffer {
9797
const width = this._renderer.width
9898
const height = this._renderer.height
9999
const density = this._renderer._pInst._pixelDensity
100+
const hasAlpha = this._renderer._pInst._glAttributes.alpha
100101

101102
const colorTexture = gl.createTexture()
102103
if (!colorTexture) {
@@ -111,11 +112,11 @@ class Framebuffer {
111112
gl.texImage2D(
112113
gl.TEXTURE_2D,
113114
0,
114-
gl.RGBA,
115+
hasAlpha ? gl.RGBA : gl.RGB,
115116
width * density,
116117
height * density,
117118
0,
118-
gl.RGBA,
119+
hasAlpha ? gl.RGBA : gl.RGB,
119120
gl.UNSIGNED_BYTE,
120121
null,
121122
)

0 commit comments

Comments
 (0)