开发者

Can Java2D be as fast as LWJGL and JOGL?

开发者 https://www.devze.com 2023-02-18 19:40 出处:网络
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 wh开发者_运维百科ich is simp

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 wh开发者_运维百科ich is simply a 2D side scroller. 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.

Pros:

  • Simplified engine writing: OpenGL has a high fill-rate, meaning you can redraw the screen every frame.
  • Possibility for cool 3D effects.

Cons:

  • All users needs to have a 3D card.
  • All users need to have an OpenGL driver installed. 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).
  • 3D cards eat battery, especially on old laptops. 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. 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.

My recommendation would be to use a Java2D rendering and animation framework like PulpCore to develop your game. I wish we had.


There are libraries that you can drop in to draw Java2D into OpenGL. GLG2D (my library) does this. It depends on JOGL and translates all java.awt.Graphics2D calls into OpenGL calls.

Line-drawing, especially curves, can be very slow in 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.


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). If you want the best of the both world, have a look at GLG2D as Brandon suggested above. Keep in mind that Java2D is an high level API whereas JOGL is a low level binding. You can use an high level API relying on these low level OpenGL bindings, for example JGame, Slick and LibGDX.

0

精彩评论

暂无评论...
验证码 换一张
取 消