Skip to content

Conversation

@reshma045
Copy link

Description:

In WEBGL mode, calling background(image) was forwarded directly to the renderer and treated as a color value, which caused an error. This change intercepts image-like arguments in p5.prototype.background, clears the WebGL buffers, and draws the image screen-aligned using image().

A regression unit test has been added to ensure background(image) does not
throw in WEBGL mode.

Resolves #7917

PR Checklist

@davepagurek
Copy link
Contributor

Hi, thanks for making this PR! We can avoid explicitly checking the type of the renderer here by moving this code into the 3D renderer class instead. Because it calls _renderer.background(...), it will call the background method on whatever the active renderer is, so we can add specific code for WebGL in the WebGL renderer, and it already knows it's WebGL at that point.

In this case, I think that would mean moving your code into here:

background(...args) {
const _col = this._pInst.color(...args);
this.clear(..._col._getRGBA());
}

The one difference is that in the renderer, this is the renderer and not the p5 instance, so what is currently a call to this.push() for example would turn into this._pInst.push().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WEBGL background image bug

2 participants