240
CHAPTER 9: User Interface
GLES20.glVertexAttribPointer(normHandle,
COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
VERTEX_STRIDE, normBuffer)
}
// get handle to vertex shader's textureCoords
vertexBuffer.position(COORDS_PER_VERTEX +
NORMS_PER_VERTEX)
val textureBuffer = vertexBuffer.slice()
// create a new view
vertexBuffer.rewind()
// ... and rewind the original buffer
val textureHandle =
GLES20.glGetAttribLocation(program,
"vTexture")
if(textureHandle >= 0) {
// Enable a handle to the texture coords
GLES20.glEnableVertexAttribArray(
textureHandle)
// Prepare the coordinate data
GLES20.glVertexAttribPointer(textureHandle,
COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
VERTEX_STRIDE, textureBuffer)
}
// get handle to vertex shader's
vColor member
vertexBuffer.position(COORDS_PER_VERTEX +
NORMS_PER_VERTEX + TEXTURE_PER_VERTEX)
val colorBuffer = vertexBuffer.slice()
// create a new view
vertexBuffer.rewind()
// ... and rewind the original buffer
val colorHandle =
GLES20.glGetAttribLocation(program, "vColor")
if(colorHandle >= 0) {
// Enable a handle to the vertices
GLES20.glEnableVertexAttribArray(colorHandle)
// Prepare the coordinate data
GLES20.glVertexAttribPointer(colorHandle,
COLORS_PER_VERTEX,
GLES20.GL_FLOAT, false,
VERTEX_STRIDE, colorBuffer)
}
textureUniformHandle =
GLES20.glGetUniformLocation(program,
"texture")
if(textureHandle >= 0) {
// Set
the active texture unit to
// texture unit 0.
GLES20.glActiveTexture(GLES20.GL_TEXTURE0)
// Tell the texture uniform sampler to use