Skip to content

Commit 4e4cd0e

Browse files
committed
Support background(image) in WEBGL Renderer3D
1 parent f19664a commit 4e4cd0e

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/core/p5.Renderer3D.js

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

730730
background(...args) {
731+
const a0 = args[0];
732+
733+
const isImageLike =
734+
a0 instanceof p5.Image ||
735+
a0 instanceof p5.Graphics ||
736+
a0 instanceof p5.MediaElement ||
737+
(typeof HTMLImageElement !== 'undefined' && a0 instanceof HTMLImageElement) ||
738+
(typeof HTMLVideoElement !== 'undefined' && a0 instanceof HTMLVideoElement) ||
739+
(typeof HTMLCanvasElement !== 'undefined' && a0 instanceof HTMLCanvasElement);
740+
741+
// WEBGL / 3D: support background(image)
742+
if (args.length > 0 && isImageLike) {
743+
this._pInst.clear();
744+
this._pInst.push();
745+
this._pInst.resetMatrix();
746+
this._pInst.imageMode(constants.CORNER);
747+
this._pInst.image(
748+
a0,
749+
-this._pInst.width / 2,
750+
-this._pInst.height / 2,
751+
this._pInst.width,
752+
this._pInst.height
753+
);
754+
755+
this._pInst.pop();
756+
return;
757+
}
758+
759+
// Default: background(color)
731760
const _col = this._pInst.color(...args);
732761
this.clear(..._col._getRGBA());
733762
}

0 commit comments

Comments
 (0)