SlideShare a Scribd company logo
1 of 17
Download to read offline
Porting from iOS to Android
Lessons Learned

Manish Mathai
Game Programmer@Rolocule
roloengine iOS Games
Touch Squash (2009)
Super Badminton (2010)
Flick Tennis (2011)
Motion Tennis (2013)
roloengine Android Games
Flick Tennis (2013)
…..
More coming soon
roloengine iOS Internals
•
•
•
•
•
•

Written in Obj-C
OpenGL ES 2.0 for rendering
OpenAL for audio
Custom Physics engine
Custom Animation engine
Custom asset format for models, animations
Decision time
Completely Native

vs

Hybrid approach

NDK provided “NativeActivity”

Standard UI combined with
C/C++ code invoked via JNI

Pros :● Almost Ultimate control over
memory management
● Faster (?)

Pros :● Easy access to java APIs
● Leverage standard UI

Cons :● No UI support
● Many APIs not available via NDK

Cons :● Adds GC overhead on UI
● UI communication a hassle
roloengine iOS Android Internals
•
•
•
•
•
•

Written in Obj-C C++ (NDK) & Java (UI)
OpenGL ES 2.0 for rendering
OpenAL-soft for audio
Custom Physics engine
Custom Animation engine
Custom asset format for models, animations
Rendering
• Competent OpenGL ES 2.0 implementations
from Android 2.3 onwards.
• DO NOT MIX OpenGL 1.0 & 2.0 calls.
• Recreate glBegin() / glEnd(), glPushMatrix() /
glPopMatrix semantics in 2.0 if needed.
OpenGL context creation
Pure Native a.k.a the hard way
static int engine_init_display(struct engine* engine) {
const EGLint attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE
};
EGLint w, h, dummy, format;
EGLint numConfigs;
EGLConfig config;
EGLSurface surface;
EGLContext context;
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
OpenGL context creation
eglInitialize(display, 0, 0);
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
surface = eglCreateWindowSurface(display, config, engine->app->window, NULL);
context = eglCreateContext(display, config, NULL, NULL);
if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) {
LOGW("Unable to eglMakeCurrent");
return -1;
}
return 0;
}
OpenGL context creation
Context creation in Java
GLSurfaceView mGLView = new GLSurfaceView(this);
mGLView.setRenderer(new GLRenderer());
class GLRenderer implements GLSurfaceView.Renderer {
…
public native void native_render();
public void onDrawFrame(GL10 gl) {
native_render();
}
}
OpenGL context creation
Rendering via JNI calls to C/C++
JNIEXPORT void JNICALL Java_com_example_package_native_render(JNIEnv *env_,
jobject obj_) {
// Drawing code goes here
}
OpenGL Tips
• All OpenGL calls on render thread. All UI
changes in UI thread.
• Avoid touching Java heap during the game
loop.
• Block OpenGL thread on application pause.
Audio
• Java APIs (SoundPool & Media Player) vs
Native API OpenSL ES
• OpenSL ES has a horrible & convoluted API
• OpenAL-soft - Software impl of OpenAL with
OpenEL ES as the backend
https://github.com/AerialX/openal-soft-android
C++ utils & tools
• Boost - surprisingly easy to build
https://github.com/MysticTreeGames/Boost-for-Android

Boost::Bind, Boost::IO
• tinyxml2 - small and efficient XML parser
https://github.com/leethomason/tinyxml2

• libpng + libzip for compressed textures
UI
• Android is stingy with memory (16-24MB)
• Easy to hit OOM with large bitmaps.
• Modern phones (1 GB+ RAM) too
Solution :BitmapFactory.Options options = new BitmapFactory.Options();
options.inPurgeable = true;
options.inInputShareable = true;
UI
• Layouts for all screen sizes a must, for
consistent UI placement.
• Stock android fonts are limited.
Thank You !
manish.mathai@rolocule.com

More Related Content

Viewers also liked

Viewers also liked (10)

Barthes codes theory
Barthes codes theoryBarthes codes theory
Barthes codes theory
 
Barthes 5 narrative codes
Barthes 5 narrative codesBarthes 5 narrative codes
Barthes 5 narrative codes
 
Barthes 5 narrative codes
Barthes 5 narrative codes Barthes 5 narrative codes
Barthes 5 narrative codes
 
Barthes Narrative Codes
Barthes Narrative CodesBarthes Narrative Codes
Barthes Narrative Codes
 
Propp's Character Theory
Propp's Character TheoryPropp's Character Theory
Propp's Character Theory
 
Roland barthes
Roland barthesRoland barthes
Roland barthes
 
Barthes' Enigma Code
Barthes' Enigma CodeBarthes' Enigma Code
Barthes' Enigma Code
 
Narrative
NarrativeNarrative
Narrative
 
Media narrative codes
Media narrative codesMedia narrative codes
Media narrative codes
 
Todorov’s narrative theory
Todorov’s narrative theoryTodorov’s narrative theory
Todorov’s narrative theory
 

Similar to Lessons learned from porting Roloengine from iOS to Android

Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glutsimpleok
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Prabindh Sundareson
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyManageIQ
 
NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and AngularNativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and AngularTodd Anglin
 
OpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIsOpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIsJungsoo Nam
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache CordovaHazem Saleh
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webpjcozzi
 
Unity3D Plugins Development Guide
Unity3D Plugins Development GuideUnity3D Plugins Development Guide
Unity3D Plugins Development GuideKaiJung Chen
 
Vlad Nedomovniy "Navigation with less pain"
Vlad Nedomovniy "Navigation with less pain"Vlad Nedomovniy "Navigation with less pain"
Vlad Nedomovniy "Navigation with less pain"Provectus
 
NativeScript and Angular
NativeScript and AngularNativeScript and Angular
NativeScript and AngularJen Looper
 
Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012philogb
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseJen Looper
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by stepJungsoo Nam
 
Virtual Reality in Android
Virtual Reality in AndroidVirtual Reality in Android
Virtual Reality in AndroidMario Bodemann
 

Similar to Lessons learned from porting Roloengine from iOS to Android (20)

Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
 
Opengl (1)
Opengl (1)Opengl (1)
Opengl (1)
 
Introduction to OpenGL.ppt
Introduction to OpenGL.pptIntroduction to OpenGL.ppt
Introduction to OpenGL.ppt
 
Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011Advanced Graphics Workshop - GFX2011
Advanced Graphics Workshop - GFX2011
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
 
NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and AngularNativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
NativeScript: Cross-Platform Mobile Apps with JavaScript and Angular
 
OpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIsOpenGL ES EGL Spec&APIs
OpenGL ES EGL Spec&APIs
 
Open gl
Open glOpen gl
Open gl
 
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
[JMaghreb 2014] Developing JavaScript Mobile Apps Using Apache Cordova
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
 
Unity3D Plugins Development Guide
Unity3D Plugins Development GuideUnity3D Plugins Development Guide
Unity3D Plugins Development Guide
 
Baiscs of OpenGL
Baiscs of OpenGLBaiscs of OpenGL
Baiscs of OpenGL
 
Vlad Nedomovniy "Navigation with less pain"
Vlad Nedomovniy "Navigation with less pain"Vlad Nedomovniy "Navigation with less pain"
Vlad Nedomovniy "Navigation with less pain"
 
OpenGL ES on iOS
OpenGL ES on iOSOpenGL ES on iOS
OpenGL ES on iOS
 
NativeScript and Angular
NativeScript and AngularNativeScript and Angular
NativeScript and Angular
 
Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012Leaving Flatland: Getting Started with WebGL- SXSW 2012
Leaving Flatland: Getting Started with WebGL- SXSW 2012
 
3D in Android
3D in Android3D in Android
3D in Android
 
Ignite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and FirebaseIgnite your app development with Angular, NativeScript and Firebase
Ignite your app development with Angular, NativeScript and Firebase
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
 
Virtual Reality in Android
Virtual Reality in AndroidVirtual Reality in Android
Virtual Reality in Android
 

Recently uploaded

Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 

Recently uploaded (20)

Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 

Lessons learned from porting Roloengine from iOS to Android

  • 1. Porting from iOS to Android Lessons Learned Manish Mathai Game Programmer@Rolocule
  • 2. roloengine iOS Games Touch Squash (2009) Super Badminton (2010) Flick Tennis (2011) Motion Tennis (2013)
  • 3. roloengine Android Games Flick Tennis (2013) ….. More coming soon
  • 4. roloengine iOS Internals • • • • • • Written in Obj-C OpenGL ES 2.0 for rendering OpenAL for audio Custom Physics engine Custom Animation engine Custom asset format for models, animations
  • 5. Decision time Completely Native vs Hybrid approach NDK provided “NativeActivity” Standard UI combined with C/C++ code invoked via JNI Pros :● Almost Ultimate control over memory management ● Faster (?) Pros :● Easy access to java APIs ● Leverage standard UI Cons :● No UI support ● Many APIs not available via NDK Cons :● Adds GC overhead on UI ● UI communication a hassle
  • 6. roloengine iOS Android Internals • • • • • • Written in Obj-C C++ (NDK) & Java (UI) OpenGL ES 2.0 for rendering OpenAL-soft for audio Custom Physics engine Custom Animation engine Custom asset format for models, animations
  • 7. Rendering • Competent OpenGL ES 2.0 implementations from Android 2.3 onwards. • DO NOT MIX OpenGL 1.0 & 2.0 calls. • Recreate glBegin() / glEnd(), glPushMatrix() / glPopMatrix semantics in 2.0 if needed.
  • 8. OpenGL context creation Pure Native a.k.a the hard way static int engine_init_display(struct engine* engine) { const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE }; EGLint w, h, dummy, format; EGLint numConfigs; EGLConfig config; EGLSurface surface; EGLContext context; EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  • 9. OpenGL context creation eglInitialize(display, 0, 0); eglChooseConfig(display, attribs, &config, 1, &numConfigs); eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); surface = eglCreateWindowSurface(display, config, engine->app->window, NULL); context = eglCreateContext(display, config, NULL, NULL); if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { LOGW("Unable to eglMakeCurrent"); return -1; } return 0; }
  • 10. OpenGL context creation Context creation in Java GLSurfaceView mGLView = new GLSurfaceView(this); mGLView.setRenderer(new GLRenderer()); class GLRenderer implements GLSurfaceView.Renderer { … public native void native_render(); public void onDrawFrame(GL10 gl) { native_render(); } }
  • 11. OpenGL context creation Rendering via JNI calls to C/C++ JNIEXPORT void JNICALL Java_com_example_package_native_render(JNIEnv *env_, jobject obj_) { // Drawing code goes here }
  • 12. OpenGL Tips • All OpenGL calls on render thread. All UI changes in UI thread. • Avoid touching Java heap during the game loop. • Block OpenGL thread on application pause.
  • 13. Audio • Java APIs (SoundPool & Media Player) vs Native API OpenSL ES • OpenSL ES has a horrible & convoluted API • OpenAL-soft - Software impl of OpenAL with OpenEL ES as the backend https://github.com/AerialX/openal-soft-android
  • 14. C++ utils & tools • Boost - surprisingly easy to build https://github.com/MysticTreeGames/Boost-for-Android Boost::Bind, Boost::IO • tinyxml2 - small and efficient XML parser https://github.com/leethomason/tinyxml2 • libpng + libzip for compressed textures
  • 15. UI • Android is stingy with memory (16-24MB) • Easy to hit OOM with large bitmaps. • Modern phones (1 GB+ RAM) too Solution :BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; options.inInputShareable = true;
  • 16. UI • Layouts for all screen sizes a must, for consistent UI placement. • Stock android fonts are limited.