Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet178/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   174   175   176   177   178   179   180   181   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile



213
CHAPTER 9: User Interface
init {
fetchVersion()
// Create an OpenGL ES 2.0 context
setEGLContextClientVersion(2)
// We set the 2.x context factory to use for
// the view
setEGLContextFactory()
// We set the renderer for drawing the graphics
renderer = MyGLRenderer()
setRenderer(renderer)
// This setting prevents the GLSurfaceView frame
// from being redrawn until you call
// requestRender()
renderMode = GLSurfaceView.RENDERMODE_WHEN_DIRTY
}
private fun fetchVersion() {
val activityManager =
context.getSystemService(
Context.ACTIVITY_SERVICE)
as ActivityManager
val configurationInfo =
activityManager.deviceConfigurationInfo
val vers = configurationInfo.glEsVersion
// e.g. "2.0"
supports3x = vers.split(".")[0] == "3"
minVers = vers.split(".")[1].toInt()
Log.i("LOG", "Supports OpenGL 3.x = " +
supports3x)
Log.i("LOG", "OpenGL minor version = " +
minVers)
}
private fun setEGLContextFactory() {
val EGL_CONTEXT_CLIENT_VERSION = 0x3098
// from egl.h c-source
class ContextFactory :
GLSurfaceView.EGLContextFactory {
override fun createContext(egl: EGL10,
display: javax.microedition.khronos.
egl.EGLDisplay?,
eglConfig: javax.microedition.khronos.
egl.EGLConfig?)
:javax.microedition.khronos.egl.EGLContext? {
val attrib_list =
intArrayOf(EGL_CONTEXT_CLIENT_VERSION,
2, EGL10.EGL_NONE)
val ectx = egl.eglCreateContext(display,



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   174   175   176   177   178   179   180   181   ...   223




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