Bash.tv → GitHub → itch.io

GPU-accelerated rendering with raw WebGL2 for games that need speed without an engine. Context creation and loss handling, compiling shaders with readable errors, uniforms, textures for pixel art and smooth art, premultiplied alpha, a batched sprite renderer (thousands of sprites in one draw call), render targets and fullscreen post-processing passes, resizing with devicePixelRatio, and when to...

Download skill (.zip) Files on GitHub

WebGL rendering

Most games should use an engine: PixiJS (2D, fastest to learn), Phaser (2D game framework, Bash’s game-kit-2d), or three.js (3D, game-kit-3d). Raw WebGL2 is for tiny fast renderers, custom effects, or learning. Drop-in: assets/gl.js (tested on a real GPU: 5,000 sprites in 1 draw call, all effects compiled and rendered).

import { createGL, texture, spriteBatch, renderTarget, fullscreenPass } from "./core/gl.js";
const gl = createGL(canvas);                         // throws if no WebGL2; handles context loss events
gl.onLost = () => showMessage("Graphics reset, tap to continue"); gl.onRestored = () => rebuildResources();
const atlas = texture(gl, images.atlas, { pixelArt: true });
const batch = spriteBatch(gl, 20000);
// frame:
gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight); gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT);
batch.begin(atlas);
for (const e of entities) batch.draw(e.sx, e.sy, 16, 16, e.x, e.y, 32, 32, [1, 1, 1, 1]);   // source rect → destination rect, tint
const calls = batch.end();

Post-processing: draw into renderTarget(gl, w, h) (bind its fb), then fullscreenPass(gl, FULLSCREEN_VERT, EFFECTS.crt).draw(rt.tex, {...}) (shader-development).

Rules

Black screen checklist

Console errors? Shader compile log? Viewport set after resize? Clear color alpha? Blend enabled with premultiplied textures? Y-flip (textures upside down: UNPACK_FLIP_Y_WEBGL)? Drawing to a framebuffer still bound? Positions outside clip space?