219
CHAPTER 9: User Interface
drawListBuffer.capacity() *
BYTES_PER_SHORT,
drawListBuffer, GLES20.GL_STATIC_DRAW)
GLES20.glBindBuffer(
GLES20.GL_ARRAY_BUFFER, 0);
GLES20.glBindBuffer(
GLES20.GL_ELEMENT_ARRAY_BUFFER, 0)
} else {
//TODO:
some error handling
}
}
The draw() method performs the rendering, as is the case
for the triangle class we
described earlier.
fun draw() {
// Add program to OpenGL ES environment
GLES20.glUseProgram(program!!)
// Get handle to fragment shader's
vColor member
colorHandle = GLES20.glGetUniformLocation(
program!!, "vColor")
// Set color for drawing the quad
GLES20.glUniform4fv(colorHandle!!, 1, color, 0)
// Get handle to vertex shader's
vPosition member
positionHandle = GLES20.glGetAttribLocation(
program!!, "vPosition")
// Enable a handle to the vertices
GLES20.glEnableVertexAttribArray(
positionHandle!!)
//
Prepare the coordinate data
GLES20.glVertexAttribPointer(positionHandle!!,
COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
VERTEX_STRIDE, vertexBuffer)
// Draw the quad
GLES20.glBindBuffer(
GLES20.GL_ARRAY_BUFFER, vbo[0]);
//
Bind Attributes
GLES20.glBindBuffer(
GLES20.GL_ELEMENT_ARRAY_BUFFER, ibo[0])
GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP,
drawListBuffer.capacity(),
GLES20.GL_UNSIGNED_SHORT, 0)