As the functions already exists in native code the only thing that is needed is to bind these functions to Java methods. To do this we create two native methods (one for glDrawElements and one for glVertexAttribPointer) and call the pre-existing OpenGL functions in native code. The source of the native code is named GLES20Fix.c and put inside the jni folder in the root of your project (create the folder if it doesn't exist). It should look like this:
#include <jni.h> #include <GLES2/gl2.h> void my_packagepath_GLES20Fix_glDrawElements(JNIEnv *env, jclass c, jint mode, jint count, jint type, jint offset) { glDrawElements(mode, count, type, (void *) offset); } void my_packagepath_GLES20Fix_glVertexAttribPointer( JNIEnv *env, jclass clazz, jint index, jint size, jint type, jboolean normalized, jint stride, jint offset) { glVertexAttribPointer(index, size, type, normalized, stride, (void *) offset); }where my_package is changed to the package where the class containing the Java methods is - in this case the class is called GLES20Fix.
The Java class must declare the two native methods and should also load the jni library during initialization (unless you want to load it elsewhere).
package my.packagepath; public class GLES20Fix { native public static void glVertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset); native public static void glDrawElements(int mode, int count, int type, int offset); private GLES20Fix() {} static { System.loadLibrary("GLES20Fix"); } }
NDK Builder
Native code needs to be compiled and put inside the obj folder in the root of the project. This can be done by using a NDK builder for Eclipse which can be created by following this walkthrough. The builder needs a makefile for the GLES20Fix.c which must be named Android.mk and put inside the jni folder. The following is an example of a makefile for GLES20Fix.c
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := GLES20Fix LOCAL_SRC_FILES := GLES20Fix.c LOCAL_LDLIBS := -llog -lGLESv2 -ldl include $(BUILD_SHARED_LIBRARY)