I'm super new to WebGL and trying to run the below portion of my code, but it's not working. I'm following an exercise in my textbook for approximating a sphere object using subdivision. Trying to follow the same basic concept that I used for the Sierpinski Gasket.
//Specifiy four vertices for a tetrahedron
var va = vec4(0.0, 0.0, -1.0, 1);
var vb = vec4(0.0, 0.942809, 0.333333, 1);
var vc = vec4(-0.816497, -0.471405, 0.333333, 1);
var vd = vec4(0.816497, -0.471405, 0.333333, 1);
var pointsArray = [];
var numTimesToSubdivide = 8;
//Adding vertex positions to a vertex array
function triangle(a, b, c)
{
pointsArray.push(a);
pointsArray.push(a);
pointsArray.push(a);
index += 3;
}
//Tetrahedron midpoint subdivision
function divideTriangle(a, b, c, count)
{
if(count > 0) {
var ab = normalize(mix(a, b, 0.5), true);
var ac = normalize(mix(a, c, 0.5), true);
var bc = normalize(mix(b, c, 0.5), true);
divideTriangle(a, ab, ac, count - 1);
divideTriangle(ab, b, bc, count - 1);
divideTriangle(bc, c, ac, count - 1);
divideTriangle(ab, bc, ac, count - 1);
}
else {
triangle(a, b, c);
}
}
//Dividing four sides of the tetrahedron
function tetrahedron(a, b, c, d, n)
{
divideTriangle(a, b, c, n);
divideTriangle(d, c, b, n);
divideTriangle(a, d, b, n);
divideTriangle(a, c, d, n);
}
//Initiate recursion
tetrahedron(va, vb, vc, vd, numTimesToSubdivide);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(pointsArray), gl.STATIC_DRAW);
gl.drawArrays(gl.TRIANGLES, 0, pointsArray.length / 2);
}
Getting this error
Uncaught ReferenceError: index is not defined
Appreciate any help.