Spaces:
Running
Running
glyphs
Browse files- config.js +3 -1
- index.html +7 -9
config.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1 |
// config.js
|
2 |
|
3 |
const config = {
|
4 |
-
glyphsAcrossTexture: 16
|
|
|
|
|
5 |
};
|
6 |
|
7 |
export { config }
|
|
|
1 |
// config.js
|
2 |
|
3 |
const config = {
|
4 |
+
glyphsAcrossTexture: 16,
|
5 |
+
glyphWidth: 32,
|
6 |
+
glyphHeight: 40
|
7 |
};
|
8 |
|
9 |
export { config }
|
index.html
CHANGED
@@ -13,8 +13,6 @@
|
|
13 |
import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
|
14 |
import { fetchShaderCode } from './utility.js';
|
15 |
import { config } from './config.js';
|
16 |
-
const glyphWidth = 32;
|
17 |
-
const glyphHeight = 40;
|
18 |
function generateGlyphTextureAtlas() {
|
19 |
const canvas = document.createElement('canvas');
|
20 |
canvas.width = 512;
|
@@ -25,9 +23,9 @@
|
|
25 |
ctx.textAlign = 'center';
|
26 |
ctx.fillStyle = 'white';
|
27 |
for (let c = 33, x = 0, y = 0; c < 128; ++c) {
|
28 |
-
ctx.fillText(String.fromCodePoint(c), x + glyphWidth / 2, y + glyphHeight / 2);
|
29 |
-
x = (x + glyphWidth) % canvas.width;
|
30 |
-
if (x === 0) y += glyphHeight;
|
31 |
}
|
32 |
return canvas;
|
33 |
}
|
@@ -81,8 +79,8 @@
|
|
81 |
|
82 |
function generateGlyphVerticesForText(s, colors = [[1, 1, 1, 1]]) {
|
83 |
const vertexData = new Float32Array(maxGlyphs * floatsPerVertex * vertsPerGlyph);
|
84 |
-
const glyphUVWidth = glyphWidth / glyphCanvas.width;
|
85 |
-
const glyphUVHeight = glyphHeight / glyphCanvas.height;
|
86 |
let offset = 0, x0 = 0, y0 = 0, x1 = 1, y1 = 1, width = 0;
|
87 |
let colorNdx = 0;
|
88 |
|
@@ -97,8 +95,8 @@
|
|
97 |
const cIndex = c - 33;
|
98 |
const glyphX = cIndex % config.glyphsAcrossTexture;
|
99 |
const glyphY = Math.floor(cIndex / config.glyphsAcrossTexture);
|
100 |
-
const u0 = glyphX * glyphWidth / glyphCanvas.width;
|
101 |
-
const v1 = glyphY * glyphHeight / glyphCanvas.height;
|
102 |
const u1 = u0 + glyphUVWidth;
|
103 |
const v0 = v1 + glyphUVHeight;
|
104 |
width = Math.max(x1, width);
|
|
|
13 |
import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
|
14 |
import { fetchShaderCode } from './utility.js';
|
15 |
import { config } from './config.js';
|
|
|
|
|
16 |
function generateGlyphTextureAtlas() {
|
17 |
const canvas = document.createElement('canvas');
|
18 |
canvas.width = 512;
|
|
|
23 |
ctx.textAlign = 'center';
|
24 |
ctx.fillStyle = 'white';
|
25 |
for (let c = 33, x = 0, y = 0; c < 128; ++c) {
|
26 |
+
ctx.fillText(String.fromCodePoint(c), x + config.glyphWidth / 2, y + config.glyphHeight / 2);
|
27 |
+
x = (x + config.glyphWidth) % canvas.width;
|
28 |
+
if (x === 0) y += config.glyphHeight;
|
29 |
}
|
30 |
return canvas;
|
31 |
}
|
|
|
79 |
|
80 |
function generateGlyphVerticesForText(s, colors = [[1, 1, 1, 1]]) {
|
81 |
const vertexData = new Float32Array(maxGlyphs * floatsPerVertex * vertsPerGlyph);
|
82 |
+
const glyphUVWidth = config.glyphWidth / glyphCanvas.width;
|
83 |
+
const glyphUVHeight = config.glyphHeight / glyphCanvas.height;
|
84 |
let offset = 0, x0 = 0, y0 = 0, x1 = 1, y1 = 1, width = 0;
|
85 |
let colorNdx = 0;
|
86 |
|
|
|
95 |
const cIndex = c - 33;
|
96 |
const glyphX = cIndex % config.glyphsAcrossTexture;
|
97 |
const glyphY = Math.floor(cIndex / config.glyphsAcrossTexture);
|
98 |
+
const u0 = glyphX * config.glyphWidth / glyphCanvas.width;
|
99 |
+
const v1 = glyphY * config.glyphHeight / glyphCanvas.height;
|
100 |
const u1 = u0 + glyphUVWidth;
|
101 |
const v0 = v1 + glyphUVHeight;
|
102 |
width = Math.max(x1, width);
|