Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet187/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   183   184   185   186   187   188   189   190   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile



231
CHAPTER 9: User Interface
The draw() method for rendering the graphics this time reads as follows:
fun draw() {
// Add program to OpenGL ES environment
GLES20.glUseProgram(program!!)
// 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)
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Buffer offsets are a little bit strange in the
// Java binding - for the normals and colors we
// create new views and then reset the vertex
// array
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// get handle to vertex shader's vPosition member
vertexBuffer.position(COORDS_PER_VERTEX)
val normBuffer = vertexBuffer.slice()
// create a new view
vertexBuffer.rewind()
// ... and rewind the original buffer
val normHandle = GLES20.glGetAttribLocation(
program, "vNorm")
if(normHandle >= 0) {
// Enable a handle to the vertices
GLES20.glEnableVertexAttribArray(normHandle)
// Prepare the coordinate data
GLES20.glVertexAttribPointer(normHandle,
COORDS_PER_VERTEX,
GLES20.GL_FLOAT, false,
VERTEX_STRIDE, normBuffer)
}
// get handle to vertex shader's vColor member
vertexBuffer.position(COORDS_PER_VERTEX +
NORMS_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) {



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   183   184   185   186   187   188   189   190   ...   223




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