Pro Android with Kotlin


CHAPTER 9: User Interface


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



221
CHAPTER 9: User Interface
fun onSurfaceCreated(gl: GL10?, config:
javax.microedition.khronos.egl.EGLConfig?) {
// enable face culling feature
GLES20.glEnable(GL10.GL_CULL_FACE)
// specify which faces to not draw
GLES20.glCullFace(GL10.GL_BACK)
// Set the background frame color
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f)
}
// Called for each redraw of the view.
// If renderMode =
// GLSurfaceView.RENDERMODE_WHEN_DIRTY
// (see MyGLSurfaceView)
// this will not be called every frame
override
fun onDrawFrame(unused: GL10) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT)
triangle = triangle ?: Triangle()
triangle?.draw()
quad = quad ?: Quad()
quad?.draw()
}
override
fun onSurfaceChanged(unused: GL10, width: Int,
height: Int) {
GLES20.glViewport(0, 0, width, height)
}
}
Projection
Once we start using the third dimension, we need to talk about projection. The projection 
describes how the three dimensions of the vertices get mapped to two-dimensional screen 
coordinates. The Triangle and Quad graphics primitives we built so far both use their own 
shader program. While this gives us the maximum flexibility, to avoid a proliferation of 
shader programs, it is better to extract the shader program and use just one from inside the 
renderer. Also, the projection calculation then needs to be done at only one place.
In addition, we let the renderer prepare N times two buffer objects, one pair of vertex and 
index buffer per object, and provide corresponding handles to each graphics primitive 
constructor. The new Square class then looks like the following:
class Square(val program: Int?,
val vertBuf:Int, val idxBuf:Int) {
val vertexBuffer: FloatBuffer
val drawListBuffer: ShortBuffer



Download 5.42 Mb.

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




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