What are some faster alternatives to Java2d?

2019-03-24 02:59发布

问题:

I'm looking to do some physics simulations and I need fast rendering in Java.

I've run into performance issues with Java2d in the past, so what are the fast alternatives? Is JOGL significantly faster than Java2d?

回答1:

My experience with Java2D is that it can be very fast, if you follow the rules. I had an application that went from 90% CPU to less than 5% CPU just by changing a few simple things. Using large transparent PNG's is a no no, for example.

A very good resource is the Java-Gaming.org forums: a lot of people, including the Sun 2D specialists, hang out there and provide many examples and solutions to performance issues for 2D drawing.

See: http://www.javagaming.org/ and then the topic "Performance Tuning".



回答2:

JOGL might be much faster than Java2D even if you use it for doing 2D graphics only: as Clayworth mentioned, it usually depends on what you need to do.

My guess is that for 2D physical simulations, where you have (textured or non-textured) objects rotating and translating with 2 degrees of freedom, JOGL should provide the best performance and also easily allow you to provide a zoomable interface. Here is a tutorial for OpenGL for 2D graphics (C, but easily adapted to JOGL).

JOGL will take a bit more time to learn than Java2D, but achieving good performance will most probably not require specialized optimizations as in Java2D.



回答3:

I don't know - in the past I'd have said yes - especially if you use display lists rather than making lots of calls through the API each time the screen is displayed. But update 10 of the 1.6 JVM added accelerated Java2D graphics, so may have the advantage now. Really the only way to know for sure is to try to render typical scenes in both and measure it.



回答4:

Also check out Slick, which is based on LWJGL and is in some ways similar to Java2D. It uses OpenGL and is thus greatly faster.