Writing a portable Java application using JOGL and

2019-03-15 21:27发布

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?

4条回答
干净又极端
2楼-- · 2019-03-15 22:00

As JOGL-ES was merged into JOGL 2.x several years ago, you can now use JOGL both in desktop and mobile environments (Android).

查看更多
贼婆χ
3楼-- · 2019-03-15 22:14

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.

查看更多
你好瞎i
4楼-- · 2019-03-15 22:19

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.

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-03-15 22:20

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.

查看更多
登录 后发表回答