使用JOGL和Android OpenGL编写一个可移植的Java应用程序

[英]Writing a portable Java application using JOGL and Android OpenGL


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.

我计划写一个Java 3D游戏,可以在PC和Android上运行。不幸的是,这两个平台似乎都没有通用的OpenGL API。

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

api有显著的不同吗?有没有办法在两个版本中使用相同的3D代码?这是个好主意吗?

4 个解决方案

#1


10  

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.

Android支持OpenGL ES 1.0,它与OpenGL 1.3重叠,所以这应该是可能的,但它并不是简单的在运行时替换jar文件。

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.

在两个平台上尽可能多地重用应用程序是一个好主意。无论如何,将其余代码与外部依赖(比如OpenGL)隔离通常是一个很好的实践,即使您并不特别需要OpenGL ES支持。您永远不知道将来希望将应用程序移植到什么API/平台。

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.

首先,将OpenGL实现隐藏在应用程序其余部分使用的接口后面,然后提供单独的Jogl和Androide实现。根据您正在运行的平台,您可以选择使用工厂模式在运行时实例化正确的实现。

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.

由于OpenGL ES和OpenGL非常相似,如果您坚持使用公共功能,那么维护它所需的工作量不应该太高。

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.

另一种选择是尝试使用Jogl2,它支持配置文件。这些似乎提供了您所需要的东西,但是Jogl2仍在测试中。

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

这个页面的底部介绍了一些配置文件: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.

概要文件允许以允许同时兼容多个OpenGL版本的方式编写Java应用程序。由于OpenGL ES(用于嵌入式系统的GL)与OpenGL本身有重叠的功能,它甚至提供了添加连接桌面和嵌入式实现的概要文件的机会。

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

您可能希望阅读http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explain以了解更多关于配置文件的信息。

#2


4  

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.

项目完成。结果发现api有所不同,但在功能上有一个共享部分。最后,我们编写了一个简单的预处理器,将JOGL代码转换为ES版本,并使用Eclipse自动执行转换。

#3


1  

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.

实际上,java3d和android opengl api之间有很大的不同。首先,java3d是3d的高级抽象。即使你使用像JOGL这样的东西在api中也会有一些不同。最好的办法是在代码库中抽象出实际的3d绘图实现,您可以共享其余的逻辑,但是有特定于平台的代码来处理opengl/3d绘图。

#4


1  

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

当JOGL- es合并到JOGL 2中。几年前,您可以在桌面和移动环境(Android)中使用JOGL。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2009/10/24/733e5161c44200ec18ad367edb6b5e87.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号