Search code examples
opengl-esandroid-ndkjava-native-interface

Drawing simple Triangle with OpenGLES in Android Studio using only C++ code and JNI


I'm learning using OpenGL ES with the JNI (Java Native Interface). I'm currently trying to draw a simple Triangle with NDK installed in Android Studio through this example : https://github.com/googlesamples/android-ndk/tree/master/hello-gl2.

I haven't learnt java before, so I want to write all the code in C++ and call it through the JNI. However, there's still some java code in the GL2JNIView.java of this example, which makes me confused. Could someone guide me how to draw this Triangle with only C++ code and call those functions through JNI please ?


Solution

  • In the sample, hello-gl2, there is no java code draws a triangle. The sample project is exactly what you are looking for. In the sample, Java only calls C++ code(which actually draws a triangle) through JNI.

    If you really don't like to use java at all, there is an option that you can use a native-activity. However, I recommend to mix Java & c++ since the android native environment is limited to use all android features that you might need. I, for example, use c++ most in android development although very barely, I need to use android api which is only supported in JAVA.

    If I used the native-activity, there wouldn't be no option to use them I needed