plasma-arc / utility.js
p3nGu1nZz's picture
cleanup
4313cb9
raw
history blame
739 Bytes
// utility.js
export async function fetchShaderCode(url) {
const response = await fetch(url);
return await response.text();
}
export function generateGlyphTextureAtlas(canvas, ctx, config) {
canvas.width = config.canvas.width;
canvas.height = config.canvas.height;
ctx.font = config.context.font
ctx.textBaseline = config.context.textBaseline;
ctx.textAlign = config.context.textAlign;
ctx.fillStyle = config.context.fillStyle;
for (let c = 33, x = 0, y = 0; c < 128; ++c) {
ctx.fillText(String.fromCodePoint(c), x + config.glyphWidth / 2, y + config.glyphHeight / 2);
x = (x + config.glyphWidth) % canvas.width;
if (x === 0) y += config.glyphHeight;
}
return canvas;
}