views:

1185

answers:

3

I plan on writing a Java 3D game that will work both on PC and Android. Unfortunately it looks like there is no common OpenGL API for both platforms.

Do the APIs differ significantly? Is there a way I could use the same 3D code in both versions? Is it a good idea?

A: 

There is actually quite a bit of difference between java3d and the android opengl api. First java3d is a higher level abstraction on 3d. And even if you were to use something like JOGL there would be some differences in the api's. Your best bet would be to abstract out the actually 3d drawing implementation in the code base, you could share the rest of the logic, but then have platform specific code to handle the opengl/3d drawing.

broschb
+5  A: 

Android supports OpenGL ES 1.0 which overlaps with OpenGL 1.3 so this should be possible, but it is not as simple a just replacing the jar files at runtime.

It is a good idea to try to reuse as much as possible of you application across both platforms. Anyway it is generally good practice to isolate the rest of you code from external dependencies such OpenGL even if you don't specifically need OpenGL ES support. You never know what API/platform you may want to port your application to in the future.

There are 2 options that are available.

The first is to hide the OpenGL implementation behind an interface that the rest of your application uses and then provide separate Jogl and Androide implementations. Depending on which platform you are running on you can then choose to instanciate the correct implemenation at runtime using the factory pattern.

As OpenGL ES and OpenGL are very similar the effort required to maintain this should not be too high providing you stick to the common functions.

The other option is to try and use Jogl2 which has support for profiles. These appear to provide exactly what you need but Jogl2 is still in beta.

The bottom this page talks a little about profiles: http://kenai.com/projects/jogl/pages/FAQ

Profiles allow Java applications to be written in a way which allows compatibility with multiple OpenGL versions at the same time. Since OpenGL ES (GL for embedded systems) has overlapping functionality with OpenGL itself it opened the opportunity to add even Profiles which bridge desktop and embedded implementations.

You might want to read this http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explained for more information about profiles.

Aaron
Very nicely researched answer. There is a nice OS JOGL application called worldwind, which I work on and I would pay to see it run on Android.
whatnick
+1  A: 

The project is finished. It turned out the APIs differ somewhat, but functionally there is a shared part. We ended up writing a simple preprocessor that converted JOGL code to ES version, and automated the conversion with Eclipse.

hmp