A computer thinks I write like
David Foster Wallace
Thu 2010-01-07 ( En pr pi )

WebGL has no text rendering functions. But it’s pretty easy to create a texture with text using canvas 2D context:

Looks best in Safari. Firefox has some strange issues with the font rendering.

You need a WebGL-enabled browser to see this.

The interesting code:

// an invisible CANVAS element, 512x512 pixels
<canvas id="textureCanvas" style="display:none" width="512" height="512"></canvas>
var textureCanvas = document.getElementById('textureCanvas')
var ctx = canvas.getContext('2d');
 
// showcase live rendering by writing the current time
var date = new Date();
function two(number) {
  if (number < 10)
    return '0' + number;
  else
    return number;
}
var text = two(date.getHours()) + ':' +
  two(date.getMinutes()) + ':' +
  two(date.getSeconds());
 
// let the color of the box rotate every minute
var secs = date.getSeconds() + date.getMilliseconds() / 1000;
ctx.fillStyle = 'hsl(' + 360 * (secs / 60) + ',100%,50%)';
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
 
// write white text with black border
ctx.fillStyle = 'white';
ctx.lineWidth = 2.5;
ctx.strokeStyle = 'black';
ctx.save();
ctx.font = 'bold 80px Verdana';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
var leftOffset = ctx.canvas.width / 2;
var topOffset = ctx.canvas.height / 2;
ctx.strokeText(text, leftOffset, topOffset);
ctx.fillText(text, leftOffset, topOffset);
ctx.restore();
 
// bind our canvas to a 2D texture
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, textureCanvas);
gl.bindTexture(gl.TEXTURE_2D, null);

Say something! / Sag was!

This is a great example but it doesn't work for me, with webGL enabled. I have tried with 440.0 and 461.0 (ie latest) versions of chromium. 
The console writes: Calling obsolete texImage2D(GLenum target, GLint level, HTMLCanvasElement canvas)

I can't find any notes on this error on the web... :(
Tom @ 04:11 on Friday, 2010-07-09
Yes you're right! I have no idea at the moment, and no time to fix it. Sorry.

It works in Firefox though.
murphy @ 17:13 on Friday, 2010-07-09
Yes, it works for me in firefox too, thanks for the hint. Must be a teething bug with Chrome.
Tom @ 14:18 on Sunday, 2010-07-11
I found the problem, it is simply that Chrome requires the canvas to be a power of 2 rather than 400*400. I made it 512*512 and it works! but 128*64 etc would also work.
Tom @ 02:55 on Friday, 2010-07-16
Thanks, Tom! I fixed it.

I thought I tried this before, because I heard about the power-of-2 issue, but it seems I didn't do it right.
murphy @ 18:18 on Sunday, 2010-07-18

No markup, just plain monospace text. / Kein Markup, nur Normschrift-Klartext.