function drawScene2 () {
window.requestAnimationFrame(drawScene2)
animateModelMatrix()
glMatrix.mat4.multiply(modelViewMat, viewMat, modelMat)
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
gl.useProgram(shaderProgram2)
gl.uniformMatrix4fv(shaderProgramInfo2.uniforms.projMat, false, projMat)
gl.uniformMatrix4fv(shaderProgramInfo2.uniforms.modelViewMat, false, modelViewMat)
gl.activeTexture(gl.TEXTURE0)
gl.bindTexture(gl.TEXTURE_2D, cubeTexture)
gl.uniform1i(shaderProgramInfo2.uniforms.textureImg, 0)
gl.bindBuffer(gl.ARRAY_BUFFER, vtxPosBuf)
// Specify layout of our vertex buffer.
// This flexibility offered by this function is most useful if you're using
// interleaved buffers, which we aren't.
//
// Arguments: attribute location, number of components per attribute, data type, normalized, stride
// Stride = "offset in bytes between the beginning of consecutive vertex attributes"
// 0 sets stride = number of components per attribute * component data type size
// Offset = "offset in bytes of the first component in the vertex attribute array"
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer
gl.vertexAttribPointer(shaderProgramInfo2.attribs.position, 3, gl.FLOAT, false, 0, 0)
// Enable our attribute location (basically: we bound useful data to it and
// the shader is going to access it)
gl.enableVertexAttribArray(shaderProgramInfo2.attribs.position)
//
// NEW in Part 2!
//
gl.bindBuffer(gl.ARRAY_BUFFER, vtxTexCoordBuf)
// Second argument is 2 instead of 3 because texture coordinates are 2D vectors
gl.vertexAttribPointer(shaderProgramInfo2.attribs.texCoord, 2, gl.FLOAT, false, 0, 0)
gl.enableVertexAttribArray(shaderProgramInfo2.attribs.texCoord)
// Bind our index buffer
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuf)
// Issue a draw call!
//
// A "draw call" is a special API call that actually draws content on the screen
// So far, we've spent hundreds of lines of code setting up the pipeline, but
// nothing has been rendered yet.
// This call tells WebGL that we're done configuring things and want to use the
// resources we've bound to produce some graphical output.
//
// Arguments: mode (primitive type), number of elements, element data type, offset
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/drawElements
gl.drawElements(gl.TRIANGLES, cubeIndexArray.length, gl.UNSIGNED_SHORT, 0)
}