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

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

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.