Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some faster alternatives to Java2d?

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?

like image 623
KingNestor Avatar asked Mar 02 '09 14:03

KingNestor


3 Answers

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".

like image 55
Rogier Avatar answered Nov 02 '22 10:11

Rogier


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.

like image 5
Lale Avatar answered Nov 02 '22 08:11

Lale


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.

like image 4
Pete Kirkham Avatar answered Nov 02 '22 10:11

Pete Kirkham