
112 7. Teaching an Introductory Computer Graphics Course with WebGL
where gl is our WebGL context, we will get an error message because WebGL expects
asimple C-like array comprising oating-point numbers.
ere are two main ways to get around this problem. One is to use JS typed arrays,
which are equivalent to C-type arrays, as in the code:
var vertices = new Float32Array([
-0.5, -0.5,
-0.5, 0.5,
0.5, 0.5,
0.5, -0.5
]);
is method works with gl.buffe rData(). Typed arrays have become standard for
doing numerical applications with JavaScript as they are more ecient. ere are packages
such as glMatrix.js
*
for doing basic linear algebra with typed a