WGLT - WebGL Terminal
- Fast, lightweight, terminal emulator using WebGL
- 100% TypeScript
- MIT license open source
- ~30kb minified JS, ~10kb gzipped
- No external dependencies
What is it?
WGLT is a JavaScript/TypeScript library for creating ASCII games in the browser.
WGLT is absurdly overoptimized for performance, using WebGL for minimal CPU.
WGLT is modelled after libtcod and rot.js.
Install
Add dependency:
npm i -D wglt
Import library:
import { Colors, Terminal } from 'wglt';
Usage
Use it:
import { Colors, Terminal } from 'wglt';
const term = new Terminal(document.querySelector('canvas'), 80, 45);
term.fillRect(0, 0, 80, 45, 0, Colors.YELLOW, Colors.DARK_BLUE);
let x = 10;
let y = 10;
term.update = () => {
const moveKey = term.getMovementKey();
if (moveKey) {
x += moveKey.x;
y += moveKey.y;
}
term.clear();
term.drawString(1, 1, 'Hello world!');
term.drawString(1, 3, 'Use arrow keys to move');
term.drawString(x, y, '@');
};
Examples
- Hello world - Basic setup, rendering, and keyboard controls
- Performance - Smooth and consistent 60 fps without CPU fan
- Colors - True color palette, HSV color manipulation
- Shmup - Simple Galaga clone demonsrating realtime gameplay
- Custom Font - Use custom font image with non-square size
- Field of View - Fast and accurate shadowcasting using MRPAS
- Path Finding - Fast and accurate routing using Dijkstra's algorithm
- Alpha Blending - Use "additive" blending to create light effects
- Flame - Procedurally generated fire effect
- Matrix Rain - Green falling text effect
- GUI - Message boxes and select dialogs
- Custom GUI - Custom dialog renderers for special effects
- Image Loading - Load an image from a URL and render as ASCII
- Image 2x - Double resolution using extended ASCII block characters
- Box Utils - Utility methods for working with box-drawing
- CRT - Scanlines, vignette, chromatic aberration example on SMTPE test image
- Roguelike - Full implementation of the classic Rogue Basin Complete Roguelike Tutorial