Skip to content

Commit 57425c6

Browse files
committed
remove background if regl fails
1 parent d49f7a5 commit 57425c6

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

src/components/sim/surfaces.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ function createFbo(regl: REGL.Regl, { filter, downsample = TEXTURE_DOWNSAMPLE }:
4343
}
4444

4545
export function createRegl(c: HTMLCanvasElement) {
46+
const gl = c.getContext("webgl", {
47+
alpha: false,
48+
depth: false,
49+
stencil: false,
50+
antialias: false,
51+
});
4652
const regl = REGL({
47-
attributes: {
48-
alpha: false,
49-
depth: false,
50-
stencil: false,
51-
antialias: false,
52-
},
53-
canvas: c,
53+
gl: gl!,
5454
extensions: ["OES_texture_half_float", "OES_texture_half_float_linear"],
5555
});
5656

src/routes/index.tsx

+28-22
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,38 @@ const App = () => {
2121
window.addEventListener("resize", resize);
2222
resize();
2323

24-
const pointers = createPointers();
25-
const { regl, update, fullscreen, createSplat } = createSim(c);
26-
let t = 0;
27-
regl.frame(() => {
28-
fullscreen(() => {
29-
const red = Math.sin(t + 0) * 0.8 + 0.8;
30-
const green = Math.sin(t + 2) * 0.8 + 0.8;
31-
const blue = Math.sin(t + 4) * 0.8 + 0.8;
32-
t += 0.1;
24+
try {
25+
const pointers = createPointers();
26+
const { regl, update, fullscreen, createSplat } = createSim(c);
27+
let t = 0;
28+
regl.frame(() => {
29+
fullscreen(() => {
30+
const red = Math.sin(t + 0) * 0.8 + 0.8;
31+
const green = Math.sin(t + 2) * 0.8 + 0.8;
32+
const blue = Math.sin(t + 4) * 0.8 + 0.8;
33+
t += 0.1;
3334

34-
for (const [, pointer] of pointers) {
35-
createSplat(pointer.x, pointer.y, pointer.dx * 10, pointer.dy * 10, [red, green, blue], 0.0005);
36-
pointer.dx *= 0.5;
37-
pointer.dy *= 0.5;
38-
}
35+
for (const [, pointer] of pointers) {
36+
createSplat(pointer.x, pointer.y, pointer.dx * 10, pointer.dy * 10, [red, green, blue], 0.0005);
37+
pointer.dx *= 0.5;
38+
pointer.dy *= 0.5;
39+
}
3940

40-
update();
41+
update();
42+
});
4143
});
42-
});
4344

44-
window.addEventListener("click", function (evt) {
45-
if (evt.detail === 3) {
46-
document.body.classList.toggle("light");
47-
toggleBaseColor();
48-
}
49-
});
45+
window.addEventListener("click", function (evt) {
46+
if (evt.detail === 3) {
47+
document.body.classList.toggle("light");
48+
toggleBaseColor();
49+
}
50+
});
51+
} catch (e) {
52+
console.error(e);
53+
c.remove();
54+
document.querySelector("#logo-placeholder")!.id = "logo-img";
55+
}
5056

5157
window.onhashchange = () => {
5258
document.querySelector(window.location.hash)?.scrollIntoView();

0 commit comments

Comments
 (0)