Skip to content

Commit 7fa997e

Browse files
authored
Merge pull request #8352 from reshma045/fix-7917-dev2
Support background(image) in WEBGL Renderer3D
2 parents f557d24 + 207d50c commit 7fa997e

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

src/core/p5.Renderer3D.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,27 @@ export class Renderer3D extends Renderer {
728728
}
729729

730730
background(...args) {
731+
const a0 = args[0];
732+
733+
const isImageLike =
734+
a0 != null &&
735+
typeof a0 === 'object' &&
736+
typeof a0.width === 'number' &&
737+
typeof a0.height === 'number' &&
738+
(a0.canvas != null || a0.elt != null);
739+
740+
// WEBGL / 3D: support background(image-like)
741+
if (isImageLike) {
742+
this._pInst.clear();
743+
this._pInst.push();
744+
this._pInst.resetMatrix();
745+
this._pInst.imageMode(constants.CENTER);
746+
this._pInst.image(a0, 0, 0, this._pInst.width, this._pInst.height);
747+
this._pInst.pop();
748+
return;
749+
}
750+
751+
// Default: background(color)
731752
const _col = this._pInst.color(...args);
732753
this.clear(..._col._getRGBA());
733754
}

test/unit/visual/cases/webgl.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,4 +929,22 @@ visualSuite('WebGL', function() {
929929
screenshot();
930930
});
931931
});
932+
933+
visualSuite('background()', function () {
934+
visualTest('background(image) works in WEBGL', function (p5, screenshot) {
935+
p5.createCanvas(50, 50, p5.WEBGL);
936+
937+
const g = p5.createGraphics(50, 50);
938+
g.background(255, 0, 0);
939+
g.fill(0);
940+
g.noStroke();
941+
g.circle(25, 25, 20);
942+
943+
p5.background(0, 0, 255);
944+
p5.background(g);
945+
946+
screenshot();
947+
});
948+
});
949+
932950
});
529 Bytes
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"numScreenshots": 1
3+
}

0 commit comments

Comments
 (0)