p3nGu1nZz commited on
Commit
855be57
1 Parent(s): 0ebca5f

optimized glyph function

Browse files
Files changed (1) hide show
  1. 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 genreateGlyphTextureAtlas() {
23
- const ctx = document.createElement('canvas').getContext('2d');
24
- ctx.canvas.width = 512;
25
- ctx.canvas.height = 256;
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
- for (let c = 33; c < 128; ++c) {
 
34
  ctx.fillText(String.fromCodePoint(c), x + glyphWidth / 2, y + glyphHeight / 2);
35
- x += glyphWidth;
36
- if (x >= ctx.canvas.width) {
37
- x = 0;
38
- y += glyphHeight;
39
- }
40
  }
41
 
42
- return ctx.canvas;
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() {