Skip to main content
100%

Hello WebGL

✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on Apr 23, 2013

This example shows a solid green square rendered across the entire canvas using raw WebGL, with no external utility libraries or dependencies. The code manually compiles a vertex shader and a fragment shader from embedded script tags, creates a program, and defines a position buffer with four corner coordinates. It draws the square as a triangle fan using `context.drawArrays`, targeting a WebGL context obtained via `canvas.getContext("webgl")` with a fallback to `experimental-webgl`.

AI-generated description

Every introductory WebGL tutorial I could find uses utility libraries (e.g., Sylvester) in efforts to make the examples easier to understand. While encapsulating common patterns is desirable when writing production code, I find this practice highly counterproductive to learning because it forces me to learn the utility library first (another layer of abstraction) before I can understand the underlying standard. Even worse when accompanying examples use minified JavaScript…

So here’s a vanilla Hello World with no dependencies and no branching. Enjoy.

Next: Part II

gpl-3.0 Licensed

Similar vizzes