Skip to content

Commit ecd8204

Browse files
committed
feat: add wasm demos
1 parent db99458 commit ecd8204

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

public/retro-snaker/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en-US">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Deft Gallery</title>
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<script src="retro-snaker.js"></script>
8+
<script src="main.js"></script>
9+
</head>
10+
<body style="margin: 0">
11+
<canvas style="width: 100vw; height: 100vh; display: block;" id="glcanvas"></canvas>
12+
</body>
13+
</html>

public/retro-snaker/main.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Make a canvas element fit to the display window.
3+
*/
4+
function resizeCanvasToDisplaySize(canvas) {
5+
const scale = window.devicePixelRatio;
6+
const width = (canvas.clientWidth | 1) * scale;
7+
const height = (canvas.clientHeight | 1) * scale;
8+
if (canvas.width !== width || canvas.height !== height) {
9+
canvas.width = width;
10+
canvas.height = height;
11+
return true;
12+
}
13+
return false;
14+
}
15+
16+
// This loads and initialize our WASM module
17+
loadDeftApp().then((app) => {
18+
// Create the WebGL context
19+
let context;
20+
const canvas = document.querySelector("#glcanvas");
21+
context = canvas.getContext("webgl2", {
22+
antialias: true,
23+
depth: true,
24+
stencil: true,
25+
alpha: true,
26+
});
27+
28+
// Register the context with emscripten
29+
handle = app.GL.registerContext(context, {majorVersion: 2});
30+
app.GL.makeContextCurrent(handle);
31+
32+
// Fit the canvas to the viewport
33+
resizeCanvasToDisplaySize(canvas);
34+
35+
try {
36+
app._asm_main();
37+
} catch (error) {
38+
// console.error("main error", error);
39+
}
40+
41+
// // Make canvas size stick to the window size
42+
window.addEventListener("resize", () => {
43+
resizeCanvasToDisplaySize(canvas);
44+
});
45+
});

public/retro-snaker/retro-snaker.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
13.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)