It's basically a modified version of something floating around the Internet. I didn't write down where I got the original from, but here is one example I found now with some googling: https://gist.github.com/zdxerr/1261307#file-glutils-js-L182. There are many other similar implementations. I've just set zfar and znear to +/-1 and removed the $M() function call - and it's transposed because WebGL. I haven't really tried to figure out the math behind it, but in any case, it creates an orthographic projection matrix for 2D drawing.