Efficient WebGL stroking
labs.hyperandroid.com
labs.hyperandroid.com
Curiously, the line drawing functions in Ejecta[1] (which reproduces the Canvas2D API) is one of the most complicated parts of the whole project and certainly has the ugliest code of it[2]. It's fast and works reliably, but maintaining it is a nightmare.
[1] http://impactjs.com/ejecta
[2] https://github.com/phoboslab/Ejecta/blob/master/Source/Eject...
http://vimeopro.com/user20904333/nslondon/video/98274186
Nigel's written a GL based vector lib:
STROKE_LINE_WIDTH = 200 STROKE_CAP_STYLE = CAP_BUTT; STROKE_JOIN_STYLE = JOIN_ROUND; <identity transform matrix>
float xy[8]; int j = 0;
for (int i = 0; i < 4; ++i) { // x coordinate xy[j++] = 20.0f * (float)cos((i / 4.0f) * 1.7) + 128.0f; // y coordinate xy[j++] = 20.0f * (float)sin((i / 4.0f) * 1.7) + 128.0f; }
<draw stroked polygon whose points are the xy coordinates>