Spaces:
Running
Running
optimized glyph function
Browse files- index.html +10 -14
index.html
CHANGED
@@ -19,27 +19,23 @@
|
|
19 |
const glyphWidth = 32;
|
20 |
const glyphHeight = 40;
|
21 |
const glyphsAcrossTexture = 16;
|
22 |
-
function
|
23 |
-
const
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
let x = 0;
|
28 |
-
let y = 0;
|
29 |
ctx.font = '32px monospace';
|
30 |
ctx.textBaseline = 'middle';
|
31 |
ctx.textAlign = 'center';
|
32 |
ctx.fillStyle = 'white';
|
33 |
-
|
|
|
34 |
ctx.fillText(String.fromCodePoint(c), x + glyphWidth / 2, y + glyphHeight / 2);
|
35 |
-
x
|
36 |
-
if (x
|
37 |
-
x = 0;
|
38 |
-
y += glyphHeight;
|
39 |
-
}
|
40 |
}
|
41 |
|
42 |
-
return
|
43 |
}
|
44 |
|
45 |
async function main() {
|
|
|
19 |
const glyphWidth = 32;
|
20 |
const glyphHeight = 40;
|
21 |
const glyphsAcrossTexture = 16;
|
22 |
+
function generateGlyphTextureAtlas() {
|
23 |
+
const canvas = document.createElement('canvas');
|
24 |
+
canvas.width = 512;
|
25 |
+
canvas.height = 256;
|
26 |
+
const ctx = canvas.getContext('2d');
|
|
|
|
|
27 |
ctx.font = '32px monospace';
|
28 |
ctx.textBaseline = 'middle';
|
29 |
ctx.textAlign = 'center';
|
30 |
ctx.fillStyle = 'white';
|
31 |
+
|
32 |
+
for (let c = 33, x = 0, y = 0; c < 128; ++c) {
|
33 |
ctx.fillText(String.fromCodePoint(c), x + glyphWidth / 2, y + glyphHeight / 2);
|
34 |
+
x = (x + glyphWidth) % canvas.width;
|
35 |
+
if (x === 0) y += glyphHeight;
|
|
|
|
|
|
|
36 |
}
|
37 |
|
38 |
+
return canvas;
|
39 |
}
|
40 |
|
41 |
async function main() {
|