Skip to content

Conversation

@reshma045
Copy link
Contributor

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().

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates, looks great!

@davepagurek davepagurek merged commit 9166fef into processing:main Dec 18, 2025
2 checks passed
@davepagurek
Copy link
Contributor

I believe this problem also exists in p5 2.0, whose code lives in the dev-2.0 branch. Would you be interested in making similar changes there? Likely the change would go in the Renderer3D file.

@davepagurek
Copy link
Contributor

@all-contributors please add @reshma045 for code

@allcontributors
Copy link
Contributor

@davepagurek

@reshma045 already contributed before to code

@reshma045
Copy link
Contributor Author

I believe this problem also exists in p5 2.0, whose code lives in the dev-2.0 branch. Would you be interested in making similar changes there? Likely the change would go in the Renderer3D file.

Thanks @davepagurek. Yes, happy to take a look at the dev-2.0 branch and make a similar fix there. I’ll implement it and open a follow up PR.

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