Conditional compile #define for iOS and Android platform

I’m working on a cross platform library for iOS and Android devices. The header files for OpenGL ES are in different folders for these platforms (see end of post), so I need to #include them differently per platform. Took me a while to find the proper one to #define for the iOS platform, so here it is:

#ifdef __APPLE__
    #include "TargetConditionals.h"
#endif
 
#if (defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR))
    #define PLATFORM_IOS
#elif (defined(ANDROID))
    #define PLATFORM_ANDROID
#endif

TargetConditionals.h is where the Target_OS_IPHONE and TARGET_IPHONE_SIMULATOR are defined, and it is only available on a Mac, hence it is wrapped in __APPLE__. The second part, PLATFORM_IOS is the preprocessor macro I’ll use throughout my code.

The #elif clause takes care of Android platform.

The OpenGL ES headers are located here:

  • iOS
    • #include <OpenGLES/ES1/gl.h>
    • #include <OpenGLES/ES1/glext.h>
    • (Swap ES1 for ES2 if you’re using that)
  • Android
    • #include <GLES/gl.h>
    • #include <GLES/glext.h>
    • #include <GLES/glplatform.h>
    • #include <GLES2/gl2.h>
    • #include <GLES2/gl2ext.h>
    • #include <GLES2/gl2ext.h>

My first post

Been hesitating about what to write for my first post. Should it be an introduction? There’s already an “about” page for that. Something to warm up the theme of this blog? Hmm…

The lack of creative writing faculty in me is preventing the opening of the floodgates for more posts to come. Ok, so here’s the solution:

*Reserved for future updates*

Voilà! Now I can properly start blogging! 😛