void renderFrame() { float modelViewMatrix[16]; static int angle = 0; glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); matrixIdentityFunction(modelViewMatrix); matrixRotateX(modelViewMatrix, angle); matrixRotateY(modelViewMatrix, angle); matrixTranslate(modelViewMatrix, 0.0f, 0.0f, -10.0f); glUseProgram(simpleCubeProgram); glVertexAttribPointer(vertexLocation, 3, GL_FLOAT, GL_FALSE, 0, cubeVertices); glEnableVertexAttribArray(vertexLocation); glVertexAttribPointer(vertexColourLocation, 3, GL_FLOAT, GL_FALSE, 0, colour); glEnableVertexAttribArray(vertexColourLocation); glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, projectionMatrix); glUniformMatrix4fv(modelViewLocation, 1, GL_FALSE, modelViewMatrix); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indices); angle += 1; if (angle > 360) { angle -= 360; } LOGI("Hello From the Native Side!! - render frame"); }
JNIEXPORT void JNICALL Java_dugu9sword_esplayer_VideoTextureSurfaceRenderer_nativeDrawTexture( JNIEnv* env, jobject obj) { glClearColor(1.0f, 1.0f, 1.0f, 0.5f); glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width, height); glUseProgram(program); int textureParamHandle = glGetUniformLocation(program, "texture"); int textureCoordinateHandle = glGetAttribLocation(program, "vTexCoordinate"); int positionHandle = glGetAttribLocation(program, "vPosition"); int textureTranformHandle = glGetUniformLocation(program, "textureTransform"); int modelViewMatrixHandle = glGetUniformLocation(program, "modelViewMatrix"); int projectionMatrixHandle = glGetUniformLocation(program, "projectionMatrix"); float projectionMatrix[16]; float modelViewMatrix[16]; matrixPerspective(projectionMatrix, 45, (float)width / (float)height, 0.1f, 100); matrixIdentityFunction(modelViewMatrix); matrixRotateX(modelViewMatrix, ++angle); matrixRotateY(modelViewMatrix, ++angle); matrixTranslate(modelViewMatrix,0.0f,0.0f,-5.0f); glUniformMatrix4fv(projectionMatrixHandle, 1, GL_FALSE,projectionMatrix); glUniformMatrix4fv(modelViewMatrixHandle, 1, GL_FALSE, modelViewMatrix); glEnableVertexAttribArray(positionHandle); glVertexAttribPointer(positionHandle, 3, GL_FLOAT, false, 0, vertices); glBindTexture(GL_TEXTURE0, textures[0]); glActiveTexture(GL_TEXTURE0); glUniform1i(textureParamHandle, 0); glEnableVertexAttribArray(textureCoordinateHandle); glVertexAttribPointer(textureCoordinateHandle, 3, GL_FLOAT, false, 0, textureCoords); jclass clazz = env->GetObjectClass(obj); jfieldID f_videoTextureTransform = env->GetFieldID(clazz, "videoTextureTransform", "[F"); jfloatArray jfa_videoTextureTransform = (jfloatArray) env->GetObjectField( obj, f_videoTextureTransform); jfloat* v_videoTextureTransform = env->GetFloatArrayElements( jfa_videoTextureTransform, 0); glUniformMatrix4fv(textureTranformHandle, 1, false, v_videoTextureTransform); env->ReleaseFloatArrayElements(jfa_videoTextureTransform, v_videoTextureTransform, JNI_ABORT); // glDrawArrays(GL_TRIANGLE_FAN, 0, 4); glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_SHORT, indicies); glDisableVertexAttribArray(positionHandle); glDisableVertexAttribArray(textureCoordinateHandle); }