Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL for Android and iPhone

In discussion with some colleagues we were wondering whether OpenGL work developed for Android or iPhone are effectively interchangeable given that both support the spec.

Or is the reality of sharing OpenGL between the two platforms more a case of quirks, tweaks and not as easy as one might have hoped.

like image 323
j pimmel Avatar asked Aug 07 '09 05:08

j pimmel


People also ask

Can I use OpenGL on iOS?

OpenGL ES provides a C-based interface for hardware-accelerated 2D and 3D graphics rendering. The OpenGL ES framework ( OpenGLES. framework ) in iOS provides implementations of versions 1.1, 2.0, and 3.0 of the OpenGL ES specification.

Can I use OpenGL on Android?

Android supports OpenGL both through its framework API and the Native Development Kit (NDK).

What is enable OpenGL traces in Android?

Tracer is a tool for analyzing OpenGL for Embedded Systems (ES) code in your Android application. The tool allows you to capture OpenGL ES commands and frame by frame images to help you understand how your graphics commands are being executed.

Can I build an Android app on iOS?

To make your application work on iOS, you'll first make your code cross-platform, and then you'll reuse your cross-platform code in a new iOS application. To make your code cross-platform: Decide what code to make cross-platform. Create a shared module for cross-platform code.


2 Answers

An OpenGL implementation normally consists of two parts: 1. Platform specific part. This has function usually related to creating and displaying surfaces. 2. The OpenGL API. This part is the same on all platforms for the specific implementation of OpenGL, in the case of Android, OpenGLES 1.0.

What this means is that the bulk of your OpenGL code should be easy to port.
In C, you might have glLoadIdentity();
In Java on Android, something like gl.glLoadIdentity();

So for the bulk of your code you can cut and paste, and then search and replace prefixes like 'gl.'

Now for the fun part: you really need to be careful what version you are coding against. OpenGL for the desktop has APIs which don't exist in OpenGLES. There are also some OpenGL data types specific to each platform. In addition, you have 1.0 (e.g. Android) 1.1 (e.g. iPhone) 2.0 (e.g. iPhone GS) to deal with. The differences in API often have to do with additional hardware capability, so it's not like you can write some easy wrapper code to emulate 2.0 features in 1.0/1.1.

like image 111
emp Avatar answered Sep 19 '22 12:09

emp


OpenGL ES on Android is done according to Khronos Java GLES spec JSR239 , and wraps GL calls in something like glinst.glBindBuffer(FloatBuffer.wrap(data) ... ) OpenGL ES on iPhone is done using stock GL.h files and the same call will just look like glBindBuffer(data...)

The code will not be interchangeable and will cause many quirks, even before you get into the whole mess of differences between 1.0 1.1 and 2.0 APis.

like image 31
reflog Avatar answered Sep 19 '22 12:09

reflog