Note that a much more complete FAQ can be found at:
Frequently Asked Questions:
Q: What are those properties that speed up Java 2D’s rendering performance?
A: Check out this document for a full list: http://java.sun.com/j2se/1.5.0/docs/guide/2d/flags.html
Q: What’s the difference between BufferedImage and VolatileImage and when do I use a particular image format for displaying my sprite, jpg, png, etc?
or any of Chet’s other excellent blogs on 2D images
Q: How do I know if my Java2D images are actually being accelerated in hardware?
A: Enable JVM profiling by setting java -Dsun.java2d.trace=count in the VM arguments before running your app. Then, quit your application and look through the generated log file for D3DBlitLoops.
Q: What oses support full screen java?
A: Windows 2000 and XP are known to support full screen correctly. Other systems are still not fully catered for.
UPDATE: MacOSX supports full screen also.
Q: How do I access the pixels of a BufferedImage to do software rendering?
BufferedImage tex = //get it from somewhere byte data = (byte) tex.getRaster().getDataElements(0, 0, tex.getWidth(), tex.getHeight(), null);
or to get a reference to the actual buffer:
Q: How do I access the pixels of an Image to do software rendering? (java 1.1 - optional as we don’t want to perpetuate old stuff)
Image im = //get the image im.getSource().startProduction(ic);
ic is an object that implements the java.awt.image.ImageConsumer interface. the method setPixels(…) will be called with the data that the image contains.
Q: How to load images and preserve tranparency?
A: If the built in loaders are used, then transparency will automatically be preserved. If you are manually loading the data, then putting it into an image you need to do some work.
//BufferedImage im = new BufferedImage(width, height, type) BufferedImage im = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
This sets up the BufferedImage to be able to accept alpha values. Then one of three methods can be called to insert pixel values:
setData(Raster r) setRGB(int x, int y, int rgb) setRGB(int startX, int startY, int w, int h, int rgbArray, int offset, int scansize)
Q: What’s accelerated by opengl pipeline in 5.0
A: Check out the Chris’ blog:
How do i enable profiling like java -Dsun.java2d.trace=count when i’m running a Applet?
Either set it in the applet’s ControlPanel, or set an env. variable _JAVA_OPTIONS="-Dsun.java2d.trace=log".
You can also redirect the output to a file.
Q: How do I profile an Applet since I can’t set the appropriate properties?
A: Use AppletViewer that comes with the SDK to test and profile applets.
Q: I’m trying to blit alot of sprites to the screen and I just can’t get the performance I want out of Java2D. Are there any other options?
A: Yes. JOGL/LWJGL provide bindings to OpenGL which is more complicated but gives a finer level of control and in most cases gives better performance. You might also consider GTGE which gives you an abstraction above Java2D/OpenGL.
If you can think of extra common questions for this list post the question and answer below. I’ll tidy it up as time goes on. In addition, if you think an answer here is wrong also let us know.
[Question/Answer Contributors: immudium, CaptainJester, K.I.L.E.R, nonnus29,trembovetski, trycoon, Demonpants, blahblahblahh, Tusaki]