标签:draw contex conf 继承 mic pat java extc pre
1.新建一个类MyGLSurfaceView继承GLSurfaceView(),Activity contentView的内容设置为这个类的对象。
2.一个GLSurfaceView对象需要一个渲染对象GLRender。所以:新建一个MyGLRender继承GLSurfaceView.Renderer。在GLRender的三个方法中进行渲染相关的工作。
3.在设置setContentView之前。把一个GLRender对象传给创建的GLSurfaceView对象。
package com.screenrecord.anychat.opengl import android.content.Context import android.opengl.GLES20 import android.opengl.GLSurfaceView import android.support.v7.app.AppCompatActivity import android.os.Bundle import javax.microedition.khronos.egl.EGLConfig import javax.microedition.khronos.opengles.GL10 class OpenGL2Activity : AppCompatActivity() { var mGlSurface: GLSurfaceView? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mGlSurface = MyGLSurfaceView(this) mGlSurface?.setRenderer(MyGLRender()) setContentView(mGlSurface) } class MyGLSurfaceView(context: Context): GLSurfaceView(context){ private var mGLRender:MyGLRender ?= null init { setEGLContextClientVersion(2) mGLRender = MyGLRender() } } class MyGLRender: GLSurfaceView.Renderer{ override fun onSurfaceCreated(gl: GL10?, config: EGLConfig?) { GLES20.glClearColor(0f,0f,0f,1f) } override fun onSurfaceChanged(gl: GL10?, width: Int, height: Int) { GLES20.glViewport(0, 0, width, height) } override fun onDrawFrame(gl: GL10?) { GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT) } } }
标签:draw contex conf 继承 mic pat java extc pre
原文地址:https://www.cnblogs.com/halo-yang/p/9316094.html