I already have reasonable experience with C++ and OpenGL, and I have recently decided to try out mobile game development. After successfully creating a simple OpenGL ES Android app using Java, I researched ways to target both Android and iOS with as little rewriting code as possible. I tried using Visual Studio 2015's proudly-boasted cross-platform app development tools, but found them to be too new and therefore extremely under-documented. I could build the template projects the program gave to me, but I couldn't figure out how, given these templates, I might add assets into the game or handle touch screen input.

I have an unfortunately specific desire, too specific to find with Google. I want to make an OpenGL ES game using C++, with thin platform-specific wrappers for Android and iOS. People have asked similar questions to me (though not exactly the same), and more than one person responding has stated that what I want to do is not only possible, but relatively easy, since I don't have to worry about UI.

I tried this tutorial, but it's almost three years old and therefore probably designed for older technology, and as a result I ran into various unaccounted-for bugs. As of right now, though, that tutorial is the closest thing to what I want that I've found. Everything else is either Android-only, or recommending that I pay hundreds of dollars a year to use the Marmalade SDK. At times I feel like just writing the code twice, once in Java and once in Objective-C, but I am kept motivated by the knowledge that this solution is possible, but for some reason, not covered anywhere in any modern detail.

To summarise, I want to make an OpenGL ES game for iOS and Android, with a single C++ codebase wrapped in small amounts of platform-specific code. However, despite the fact that several people have recommended this approach, no one can tell me how to do it. Can somebody tell me if it's actually possible, and if so, what I can do or where I can go to learn how?

  • \$\begingroup\$ try cocos2d-x, or unity3d \$\endgroup\$
    – Ali1S232
    Dec 31, 2015 at 2:51
  • 1
    \$\begingroup\$ unity3d is far from what the OP is asking as you have no source access. I've used cocos2d-x and the compilation issues are still there to some degree. The Objective-C influence is felt as well, some may like that, but for me that is a turn off. It is an open source solution, however, so maybe worth the OPs time investigating. \$\endgroup\$ Dec 31, 2015 at 2:57

1 Answer 1


You may find my answer to a similar question here to be helpful.

You may also find it helpful to look into the source code of other solutions. The Godot Engine for example is a cross platform open source game engine so you never need to pay anything.

As I mention in my other answer you don't need to (and likely can't) rely on one IDE to do the work for you. CMake, Scons, and many other build tools can help with the cross compilation/build process across platforms and IDEs.

Godot Engine, for example, uses Scons and the LLVM project (aka the compiler framework used by clang the C/C++/Objective-C compiler) uses CMake.

A popular approach for games is to build an engine in C/C++ and, as you mention, abstract away platform specifics. When it comes to iOS and Android this is the life cycle management logic that interfaces with the OS. If you wanted to go the extra mile and utilize Emscripten to also compile to asm.js and realize near native speed in the browser, you are doing something similar with abstracting away the main loop behind what amounts to requestAnimationFrame calls.

Emscripten recommends the use of SDL to make the porting process easier as it can help handle abstracting the platform specifics, but there is nothing stopping you from doing this yourself (other then loads of research, debugging, etc.).

If you are really, really crazy you can do what I am doing and write your own language utilizing the power of LLVM to compile to native C ABI or even JIT on supported platforms.

The point is that yes it is indeed possible, but some roads are more complicated/time consuming then others.

Note: You will likely need to use Mac OSX via a Mac, VM, or Hackintosh with XCode to compile to iOS. This is one of many reasons I find a Macbook Pro to be a great candidate for a development system.

Note2: It is worth mentioning that many cross platform engines today utilize scripting languages for game specific logic. Unity doesn't even let you near their source code for example (although you can write native plugins). This can help speed up development cycles as well as keeping porting to a minimum as the scripting languages are fairly platform agnostic (especially interpreted languages running in a VM). The goal for my language is to allow both JIT (mostly for development time savings) and static compilation.

Note3: If you haven't found this out already. If you do not utilize SDL or some other solution that abstracts platform specifics, you will need to utilize each platform's specific C/C++ interfacing features. With iOS this is pretty simple in XCode as the compiler (clang as mentioned above) supports C/C++ already. With Android you need to utilize the NDK and marshall calls between Java and C/C++.

  • 1
    \$\begingroup\$ I looked into the source code of the Godot Engine. It seems a little excessive; I'd rather create my own without the features I don't need. I'm not quite sure how to do that, though. I haven't been able to successfully run any C++ code on Android yet. \$\endgroup\$ Dec 31, 2015 at 2:39
  • \$\begingroup\$ hehe... ya NDK is no picnic. Honestly I find anything google to need some help in the developer friendliness category. Is using the SDL off limits for you? I have much more information I can update the answer with if need be. \$\endgroup\$ Dec 31, 2015 at 2:42
  • \$\begingroup\$ SDL's not off-limits, but I'd prefer not to go there. Once again, there's always that niggling bit of knowledge that it could have been done without a framework. \$\endgroup\$ Dec 31, 2015 at 5:05
  • \$\begingroup\$ I'm constantly bitten by that bug, so I know how you feel. I have used the NDK in the past and I don't think much has changed in the way of setup and compilation. I sure hope debugging has improved as you had to use GDB directly in the past via terminal and the IDE had no support for it, but it sounds like they have started to add NDK support to android studio. Have you tried the hellojni example? \$\endgroup\$ Dec 31, 2015 at 5:26
  • \$\begingroup\$ NDK is one of the most disgusting things in existence, you might find bgfx useful as a reference github.com/bkaradzic/bgfx , it's not as thin as you might like though, it has multiple rendering backends \$\endgroup\$
    – JBeurer
    Dec 31, 2015 at 6:36

Not the answer you're looking for? Browse other questions tagged .