Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p5.min.js WEBGL behaving differently than p5.js #5890

Closed
1 of 17 tasks
wagedu opened this issue Dec 7, 2022 · 4 comments
Closed
1 of 17 tasks

p5.min.js WEBGL behaving differently than p5.js #5890

wagedu opened this issue Dec 7, 2022 · 4 comments

Comments

@wagedu
Copy link

wagedu commented Dec 7, 2022

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

p5.js version

1.5.0

Web browser and version

Firefox 102

Operating System

OSX 10.15

Steps to reproduce this

Steps:

  1. Create/place a WEBGL canvas on top of a simple one. If using p5.js, the WEBGL layer can have transparent background. If switching to p5.min.js it renders opaque

Snippet:

// Paste your code here :)
var s2d = function( sketch ) {
  sketch.setup = function() {
    let canvas1 = sketch.createCanvas(100, 100);
    canvas1.position(0,0);
  }
  sketch.draw = function() {
    sketch.background(50);
    sketch.fill(100)
    sketch.ellipse(50,50,100,100)
  }
};

new p5(s2d);

var s3d = function( sketch ) {

  let b2;

   sketch.setup = function() {
    let canvas2 = sketch.createCanvas(100, 100, sketch.WEBGL);
    b2 = sketch.createGraphics(400,400)
    b2.rect(0,0,100,100)
    canvas2.position(0,0);
  }
  sketch.draw = function() {
    //for canvas 2
    // sketch.background(100);
    sketch.clear()
    sketch.rotateX(sketch.frameCount * 0.01);
    sketch.rotateZ(sketch.frameCount * 0.02);
    sketch.cylinder(30, 50);
    sketch.image(b2,0,0)
  }
};

new p5(s3d);

Screen Shot 2022-12-07 at 20 05 09
Screen Shot 2022-12-07 at 20 05 45

@wagedu wagedu added the Bug label Dec 7, 2022
@welcome
Copy link

welcome bot commented Dec 7, 2022

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@davepagurek
Copy link
Contributor

Hi! I tried pasting your code into editor.p5js.org and then toggling between .min.js and .js but I don't see a difference between them. Is there a chance that your non-minified p5 file is from an earlier version? The .min.js output you've shown is the expected output in v1.5.0, which disables alpha by default. Alpha can be turned on by calling setAttributes({ alpha: true }) after creating your canvas.

However, I've noticed a bug when doing this! In your code, you have this:

let canvas2 = sketch.createCanvas(100, 100, sketch.WEBGL);
// ...
canvas2.position(0,0);

Unfortunately, this stops working after a setAttributes call, because setAttributes recreates the canvas element under the hood. Currently, to fix it, one would have to do:

sketch.createCanvas(100, 100, sketch.WEBGL);
sketch.setAttributes({ alpha: true });
let canvas2 = sketch._renderer;
// ...
canvas2.position(0,0);

This doesn't seem great, I wonder if there's a way that we can make the output of createCanvas stay up to date? Or maybe make setAttributes return the new renderer?

Live version here: https://editor.p5js.org/davepagurek/sketches/ZTPqeBdb9

@wagedu
Copy link
Author

wagedu commented Dec 8, 2022

Yep, my bad. As I changed the old p5.min.js for the new one, did the exact opposite with the p5.js (how?!) and ended up using an old version.
I have "framebuffer" as a shortcut search just to copy the "setAttributes" snippet every.single.time. And I also noticed it not working for me. Thanks for the workaround!

@davepagurek
Copy link
Contributor

For organizational purposes, I'm going to close this issue, but I've made a new issue with a more descriptive title for that issue where the return value of createCanvas stops being valid after setAttributes(): #5902

I've also made another issue here #5891 to discuss a potential solution to let us allow WebGL canvases to have alpha again by default. Feel free to carry on the discussions there 🙂

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

No branches or pull requests

2 participants