flok icon indicating copy to clipboard operation
flok copied to clipboard

[Hydra] WEBGL mode in P5js

Open aaronsherwood opened this issue 10 months ago • 3 comments

Can't seem to get webgl mode to work when using p5js shaders in Hydra: Uncaught Error: shader() is only supported in WEBGL mode. Here is the code:

p5 = new P5({width: window.innerWidth, height:window.innerHeight, mode: 'WEBGL'})
shader = p5.loadShader("https://raw.githubusercontent.com/aaronsherwood/liveCoding/main/Class_Examples/shaders/basic.vert", "https://raw.githubusercontent.com/aaronsherwood/liveCoding/main/Class_Examples/shaders/ocean.frag");

p5.pixelDensity(1);
p5.draw = () => {
  shader.setUniform("time", time * 0.3);
  shader.setUniform("resolution", [width, height]);
  shader.setUniform("mouse", [p5.mouseX, p5.mouseY]);
  p5.shader(shader);
  p5.rect(0, 0, width, height);
}
p5.hide();
s0.init({
  src: p5.canvas
})
src(s0).out()

This works fine in normal hydra, see here.

aaronsherwood avatar Apr 15 '24 11:04 aaronsherwood

PS I had a version of flok-web 0.4.12 on my computer and in that version it works.

aaronsherwood avatar Apr 15 '24 11:04 aaronsherwood

Typing "WEBGL" as "webgl" in lowercase seemed to fix the issue on my end. The type definitions for p5 seem to all be using lowercase values.

image

AakSin avatar Apr 23 '24 19:04 AakSin

Thanks for reporting this. That's weird, maybe the bundled version of P5 that flok uses is different from the one Hydra uses. I'll take a look.

munshkr avatar Apr 26 '24 11:04 munshkr