Minecraft text rendering inside the browser!
Find a file
2026-06-12 23:20:27 +03:00
devserver feat: transform feedback based bbox API 2026-05-08 21:18:26 +03:00
headers chore: relicense to LGPL ect. 2026-04-30 11:31:39 +03:00
scripts chore: relicense to LGPL ect. 2026-04-30 11:31:39 +03:00
src fix: match minecraft uniforms better 2026-06-12 23:20:27 +03:00
tests feat: implement ScreenSize uniform 2026-06-12 18:31:00 +03:00
.gitignore work from yesturday 2026-04-20 13:57:13 +03:00
AGENTS.md yes 2026-04-19 20:35:10 +03:00
bun.lock fix: remove self-dependency 2026-04-29 14:27:34 +03:00
LICENSE.md chore: relicense to LGPL ect. 2026-04-30 11:31:39 +03:00
logo.png yes 2026-04-19 20:57:47 +03:00
package.json fix: match minecraft uniforms better 2026-06-12 23:20:27 +03:00
README.md chore: README update 2026-05-08 02:00:21 +03:00
tsconfig.build.json work from yesturday 2026-04-20 13:57:13 +03:00
tsconfig.json fix: remove self-dependency 2026-04-29 14:27:34 +03:00

Libmojangles

A zero-dependencies TypeScript library that recreates Minecraft's font rendering stack for the web, pixel-perfect.

Note: This project has been mostly developed by LLMs, but tested heavily against the game.

Features
  • Resource Pack Support — Load Minecraft resource packs to use custom fonts, textures, and font definitions
  • Shader Pipeline — Uses Minecraft's core shaders (vertex + fragment); supports custom shaders via resource packs
  • Text Component Parsing — Full support for Minecraft JSON text components with colors, formatting, and nested extras
  • Component Bounding Boxes — Get precise bounding boxes for each text component, useful for hit detection and tooltips
  • WebGL2 Rendering — Hardware-accelerated text rendering with proper Unicode and bitmap font support
Installation
bun add libmojangles
# or
npm install libmojangles
Quick Start
import { createLibmojangles, ResourcePackZIP } from "libmojangles";

const canvas = document.getElementById("canvas") as HTMLCanvasElement;
const lib = createLibmojangles({ canvas });

// Load a resource pack from a zip file (e.g., Minecraft's assets or a custom pack)
const zipData = await fetch("/path/to/resourcepack.zip").then((r) =>
  r.arrayBuffer(),
);
const pack = await ResourcePackZIP.fromZip(zipData, "vanilla");
lib.addResourcePack(pack);

await lib.loadFont({ namespace: "minecraft", path: "default" });

lib.renderer.beginFrame();
lib.drawText("Hello World!", 10, 10, { scale: 2 });
lib.renderer.endFrame();

You can anchor text horizontally at draw time:

lib.drawText("Centered title", canvas.width / 2, 20, {
  scale: 2,
  anchorX: "center",
});
Text Components

Libmojangles supports Minecraft's JSON text component format:

lib.drawText(
  {
    extra: [{ text: "Hello " }, { text: "World!", color: "gold", bold: true }],
  },
  10,
  10,
);

Per-Component Custom Uniforms

For convenience, you can pass custom shader uniforms to specific components by ID.

lib.drawText(
  {
    extra: [
      { id: "warning", text: "WARNING: " },
      { id: "message", text: "System overheating!" },
    ],
  },
  10,
  10,
  {
    uniforms: {
      warning: { TintColor: [1, 0, 0] },
      message: { TintColor: [1, 1, 0] },
    },
  },
);
API Overview

createLibmojangles(options)

Creates a new Libmojangles instance.

Option Type Description
canvas HTMLCanvasElement Required. The canvas to render to
defaultFont ResourceLocation Optional. Default font to use

Instance Methods

Method Description
addResourcePack(pack) Add a resource pack for fonts/textures/shaders
removeResourcePack(pack) Remove a resource pack
loadFont(id) Load a font by resource location
drawText(text, x, y, options?) Draw text; returns { components } with bounding boxes when cachePicking: true
createTextMesh(text, options?) Create vertex data without rendering
pick(x, y) Get glyph info at screen position
resize(width, height) Resize the renderer
dispose() Clean up resources
Development
# Install dependencies
bun install

# Run dev server with playground
bun run dev

# Run tests
bun test
Resource Packs

You need Minecraft's vanilla assets or a compatible resource pack. The library expects the standard Minecraft resource pack structure:

Hudkit

Libmojangles was built by the Hudkit team to power Minecraft text rendering in Hudkit Studio, where it runs in production today.

License

Libmojangles is licensed under the GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later).

This means you can:

  • Use this library in proprietary applications without open-sourcing your entire project
  • Link to or import libmojangles as a dependency in any project (commercial or otherwise)
  • Modify the library for your own use

If you distribute a modified version of libmojangles itself, you must:

  • Release your modifications under LGPL-3.0 or later
  • Provide access to the modified source code

See LICENSE.md for the full license text.

Copyright (C) 2026 Perny / Hudkit