36

I'm looking to learn OpenGL ES 2.0 on Android and the tutorials I've found are nearly all for using the SDK with Java. I want to use native code however so I want to do it through the NDK. The only tutorial/example I've found is the sample-stuff in the NDK itself.

Where can I find some NDK OpenGL ES 2.0 tutorials? If there are no good tutorials out there, is it possible to use the Java OpenGL tutorials to learn how to use it in the NDK as well? For example do the methods map 1:1 from java to native?

genpfault
  • 51,148
  • 11
  • 85
  • 139
KaiserJohaan
  • 9,028
  • 20
  • 112
  • 199

3 Answers3

24

I've created an example on how to combine UI done in Java with native NDK code that does all the OpenGL rendering. It is possible to do without resorting to GLSurfaceView and JNI calls for rendering each frame like done in the NDK sample.

See the code at https://github.com/tsaarni/android-native-egl-example

tsaarni
  • 818
  • 1
  • 8
  • 18
  • Greate job, i have test the sample ,really useful,thanks, but ,there is a issue on same devices, when i set the screenOrientation to landscape,seems opengl not rendering..., – codeplay Aug 29 '13 at 06:48
  • Thanks! Could you post issue ticket on the project page and attach logcat logfile? Unfortunately I did not have too many devices to test on... – tsaarni Aug 30 '13 at 03:29
  • 1
    @tsaarni, Are you sure that your project uses `OpenGL ES 2.0`? – CAMOBAP Jul 28 '14 at 14:55
  • @CAMOBAP No, I suppose it calls only OpenGL ES 1.x functions, no dependency to GLES 2.0 as such. However it requires Android API level 9 and Android NDK r5 or later. – tsaarni Jul 29 '14 at 15:54
  • I was also looking for OpenGL ES 2.0 dependency, but your build.gradle shows that you are using version 1.x. https://github.com/tsaarni/android-native-egl-example/blob/master/build.gradle – Fuat Coşkun Feb 21 '17 at 07:31
  • @FuatCoşkun I'm not working with Android anymore but please contribute update to the example for GLES 2.0 – tsaarni Feb 22 '17 at 18:40
3

Check this link. It concerns NDK and OpenGL issues, as well as several other related to game engine programming and more. I find it very interesting and helpful.

aga
  • 27,954
  • 13
  • 86
  • 121
user2275545
  • 69
  • 1
  • 2
1

Google has a sample project on GitHub which demonstrates how to setup a EGL context from native code, using SurfaceView created in Java: Teapots sample. In particular, take a look at "more teapots" app and code in ndk_helper for context creation.

If you want to work without any Java code, then this sample should help you get started: native activity

Edit: additionally, this link gives a higher level overview of relationship between Java Surface, it's native counterpart and EGL: EGLSurfaces and OpenGL ES

joe_chip
  • 2,468
  • 1
  • 12
  • 23