简体   繁体   English

Java2D可以和LWJGL和JOGL一样快吗?

[英]Can Java2D be as fast as LWJGL and JOGL?

I've heard that Java2D uses OpenGL behind the scenes to do it's rendering, and I've wondered if it's worth it to use JOGL and all it's native libraries for my program which is simply a 2D side scroller. 我听说Java2D在幕后使用OpenGL进行渲染,我想知道是否值得使用JOGL以及它所有的本机库,我的程序只是一个2D侧卷轴。 I've heard that there are certain techniques you have to use and scenarios you need to avoid to make sure hardware acceleration is being used but I don't know what they are(well, I know a few, but I've yet to find a comprehensive list of them.). 我听说你必须使用某些技术和你需要避免的场景,以确保使用硬件加速,但我不知道它们是什么(好吧,我知道一些,但我还没有找到它们的完整列表。)

As someone who co-developed a 2D casual game in Java using LWJGL , I recommend against using LWJGL or JOGL if you're going to be making a casual game. 作为使用LWJGL在Java中共同开发2D休闲游戏的人,如果您打算制作休闲游戏,我建议不要使用LWJGL或JOGL。

Pros: 优点:

  • Simplified engine writing: OpenGL has a high fill-rate, meaning you can redraw the screen every frame. 简化的引擎写入:OpenGL具有高填充率,这意味着您可以每帧重绘一次屏幕。
  • Possibility for cool 3D effects. 可以实现炫酷的3D效果。

Cons: 缺点:

  • All users needs to have a 3D card. 所有用户都需要有一张3D卡。
  • All users need to have an OpenGL driver installed. 所有用户都需要安装OpenGL驱动程序。 Windows 7 does not come with any OpenGL drivers installed (look up " pixel format not accelerated " on Google to see the kind of fun that results in). Windows 7没有安装任何OpenGL驱动程序(在Google上查找“ 像素格式未加速 ”以查看导致的那种乐趣)。
  • 3D cards eat battery, especially on old laptops. 3D卡吃电池,尤其是旧笔记本电脑。 People often play casual games on laptops, so this can be a problem. 人们经常在笔记本电脑上玩休闲游戏,所以这可能是一个问题。
  • Applets need extra permissions to be able to use the 3D card. 小程序需要额外的权限才能使用3D卡。 This results in an scary permission dialog a user has to click through to play your game, unless you're willing to buy a $500 certificate. 除非您愿意购买500美元的证书,否则这会导致用户必须点击一个可怕的权限对话框才能玩游戏。

My recommendation would be to use a Java2D rendering and animation framework like PulpCore to develop your game. 我的建议是使用像PulpCore这样的Java2D渲染和动画框架来开发你的游戏。 I wish we had. 我希望我们有。

There are libraries that you can drop in to draw Java2D into OpenGL. 您可以使用库将Java2D绘制到OpenGL中。 GLG2D (my library) does this. GLG2D (我的图书馆)这样做。 It depends on JOGL and translates all java.awt.Graphics2D calls into OpenGL calls. 它依赖于JOGL并将所有java.awt.Graphics2D调用转换为OpenGL调用。

Line-drawing, especially curves, can be very slow in Java2D. 在Java2D中,线条绘制(尤其是曲线)可能非常慢。

Short answer, no. 简短的回答,没有。 There are simply too many bloat layers on Java2D for it be anywhere near as fast as an LWJGL or JOGL app. Java2D上有太多的膨胀层,因为它可以像LWJGL或JOGL应用程序一样快。

You can enable hardware acceleration in Java2D but even in this case it is still slower (and sometimes buggy) than any Java binding for OpenGL (JOGL, LWJGL). 您可以在Java2D中启用硬件加速,但即使在这种情况下,它仍然比任何用于OpenGL的Java绑定(JOGL,LWJGL)更慢(有时还有错误)。 If you want the best of the both world, have a look at GLG2D as Brandon suggested above. 如果你想要两全其美,请看看上面提到的Brandon建议的GLG2D。 Keep in mind that Java2D is an high level API whereas JOGL is a low level binding. 请记住,Java2D是一个高级API,而JOGL是一个低级绑定。 You can use an high level API relying on these low level OpenGL bindings, for example JGame, Slick and LibGDX. 您可以使用依赖于这些低级OpenGL绑定的高级API,例如JGame,Slick和LibGDX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM