Texture Coordinate Buffer Object

Buffer object handling is as before. However, we have a additional vertex attribute, used to represent texture coordinates.

〈Buffer Initialization〉 +≡

The texture coordinate data must converted to a flat typed array.

  texCoordArraynew Float32Array(flatten(texCoords))

And that array must be copied to an array buffer.

  gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer)
  gl.bufferData(gl.ARRAY_BUFFER, texCoordArray, gl.STATIC_DRAW)

The GLSL program attribute location must be determined.

  vertexTexCoordLocationgl.getAttribLocation(program, “vertexTexCoord”)

And finally, before rendering, the texture coordinate attribute pointer must be set and enabled.

〈Rendering〉 +≡
  gl.vertexAttribPointer(vertexTexCoordLocation, 2, gl.FLOAT, false, 0, 0)