Game Development Reference
In-Depth Information
}
function drawDartboard(){
//draw dartboard
gl.useProgram(shaderPrograms[TEXTURE_SHADER]);
mat4.identity(mvMatrix);
mat4.translate(mvMatrix, [0, 0, dartboard_z]);
setMatrixUniforms(TEXTURE_SHADER);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, dartboardTexture);
gl.uniform1i(shaderPrograms[TEXTURE_SHADER].samplerUniform, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, dartboardVertexPositionBuffer);
gl.vertexAttribPointer(vertexPositionAttributes[TEXTURE_SHADER], 3,
gl.FLOAT, false, 0, 0);
gl.bindBuffer(gl.ARRAY_BUFFER, dartboardVertexTexCoordBuffer);
gl.vertexAttribPointer(textureCoordAttributes[TEXTURE_SHADER], 2,
gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLE_FAN, 1, dartboard_sections);
}
function drawDart (){
//draw dart
}
In the drawDartboard function, we use the texture shader, reset the view to the identity, and then translate
the dartboard back along the z-axis. We set the active texture and a sampler uniform, which the fragment
shader uses. We bind our buffer data and draw the dartboard by calling drawArrays .
Figure 7-13. Dartboard image textured onto a triangle fan
 
Search WWH ::




Custom Search