@Override public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER); GLES20.glShaderSource(vertexShaderHandle, loadShader(R.raw.vertex_shader)); GLES20.glCompileShader(vertexShaderHandle); int fragmentShaderHandle = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER); GLES20.glShaderSource(fragmentShaderHandle, loadShader(R.raw.fragment_shader)); GLES20.glCompileShader(fragmentShaderHandle); int programHandle = GLES20.glCreateProgram(); GLES20.glAttachShader(programHandle, vertexShaderHandle); GLES20.glAttachShader(programHandle, fragmentShaderHandle); GLES20.glLinkProgram(programHandle); GLES20.glUseProgram(programHandle); Object3D.init(programHandle); mLightPosHandle = GLES20.glGetUniformLocation(programHandle, "uLightPos"); GLES20.glEnable(GLES20.GL_DEPTH_TEST); GLES20.glEnable(GLES20.GL_CULL_FACE); GLES20.glCullFace(GLES20.GL_BACK); // GLES20.glEnable(GLES20.GL_BLEND); // GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); mPrism.init(); mCylinder.init(); mSphere.init(); }
@Override public void onDrawFrame(GL10 glUnused) { GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); Matrix.setIdentityM(mModelMatrix, 0); Matrix.rotateM(mModelMatrix, 0, 90, 1.0f, 0.0f, 0.0f); Matrix.multiplyMM(mMVMatrix, 0, mViewMatrix, 0, mModelMatrix, 0); Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVMatrix, 0); mPrism.render(mMVPMatrix, mMVMatrix); mCylinder.render(mMVPMatrix, mMVMatrix); mSphere.render(mMVPMatrix, mMVMatrix); }
public void release() { mSphere.release(); mCylinder.release(); mPrism.release(); Object3D.releaseBuffer(); }