笔记,安卓上简单的surfaceview使用

建立基于GLSurfaceView的类:

public class MyGLSurfaceView extends GLSurfaceView {

初始化:

1. onSurfaceCreated:

a) mProgram = createProgram(mVertexShader, mFragmentShader);
   vao, vertex, coords handle
b) textures
   GLES30.glGenTextures(1, textures, 0);
   mTextureID = textures[0];
   GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);
   GLES30.glTexParameterf( ... // configure
c) SurfaceTexture mSurface;
   mSurface = new SurfaceTexture(mTextureID);
   mSurface.setOnFrameAvailableListener(this);


显示:

2. onDrawFrame:
a) mSurface.updateTexImage();

    得到一个oes纹理, 然后用这个oes纹理进行绘制
b) GLES30.glUseProgram(mProgram);
c) GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
   GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTextureID);
d) GLES30.glVertexAttribPointer(handle 
   GLES30.glEnableVertexAttribArray(handle
e) PVM
   Matrix.setLookAtM(mVMatrix,...
   Matrix.frustumM(mProjMatrix,...
   Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);   
f) GLES30.glDrawArrays(GLES30.GL_TRIANGLES, ...

你可能感兴趣的:(vr,opengl)