Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet183/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   179   180   181   182   183   184   185   186   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile



223
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: error handling
}
}
The draw() method does not substantially differ from before. This time we use the shader 
program provided in the constructor. Again, this method runs fast, since it only shifts around 
references.
fun draw() {
// Add program to OpenGL ES environment
GLES20.glUseProgram(program!!)
// get handle to fragment shader's vColor member
val colorHandle = GLES20.glGetUniformLocation(
program!!, "vColor")
// Set color for drawing the square
GLES20.glUniform4fv(colorHandle!!, 1, color, 0)
// get handle to vertex shader's vPosition member
val 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 square
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER,
vertBuf)
GLES20.glBindBuffer(
GLES20.GL_ELEMENT_ARRAY_BUFFER, idxBuf)
GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP,
drawListBuffer.capacity(),
GLES20.GL_UNSIGNED_SHORT, 0)



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   179   180   181   182   183   184   185   186   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling