Skip to content

Instantly share code, notes, and snippets.

@appspell
Created Mar 4, 2021
Embed
What would you like to do?
override fun onDrawFrame(gl: GL10?) {
// clear the our "screen"
GLES30.glClearColor(0.0f, 0.0f, 0.0f, 0.0f)
GLES30.glClear(GLES30.GL_DEPTH_BUFFER_BIT or GLES30.GL_COLOR_BUFFER_BIT)
// use program
GLES30.glUseProgram(program)
// set shader input (built-in attributes)
setAttribute(inPositionHandle, VERTEX_SHADER_IN_POSITION, 3, TRIANGLE_VERTICES_DATA_POS_OFFSET) // 3 because 3 floats for position
setAttribute(inTextureHandle, VERTEX_SHADER_IN_TEXTURE_COORD, 2, TRIANGLE_VERTICES_DATA_UV_OFFSET) // 2 because 2 floats for texture coordinates
// update matrix
Matrix.setIdentityM(matrixMVP, 0)
GLES30.glUniformMatrix4fv(uMVPMatrixHandle, 1, false, matrixMVP, 0)
GLES30.glUniformMatrix4fv(uSTMatrixHandle, 1, false, matrixSTM, 0)
// (!) update uniforms for fragment shader
val uMyUniformValue = floatArrayOf(1.0f, 0.75f, 0.95f, 1f) // some values that we're going to send to the fragment shader
GLES30.glUniform4fv(uMyUniform, 1, uMyUniformValue, 0)
// activate blending for textures (to support transparency)
GLES30.glBlendFunc(GLES30.GL_SRC_ALPHA, GLES30.GL_ONE_MINUS_SRC_ALPHA)
GLES30.glEnable(GLES20.GL_BLEND)
// draw our quad
GLES30.glDrawArrays(GLES30.GL_TRIANGLE_STRIP, 0, 4)
checkGlError("glDrawArrays")
GLES30.glFinish()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment