Next, we include texture coordinates, enabling us to send the vertices with a texture map to the shader. Texture mapping is just pasting an image onto a 3D mesh, which is similar to pasting wallpaper onto a wall. Nearly all 3D objects are drawn using texture maps because you can achieve a higher level of realism instead of just solid colors.
In initShaders()
, a new code passes an array that contains texture coordinates (which are in pairs for the vertical and horizontal directions) and there is one texture coordinate for every vertex. The texture map image is passed to the shader as a sampler, as presented in the following code:
shaderProgram.textureCoordAttribute = gl.getAttribLocation(shaderProgram, "aTextureCoord"); gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute); shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix"); shaderProgram.samplerUniform = gl.getUniformLocation(shaderProgram, "uSampler...