Hi!
It’s been a while since Sun announced graphics acceleration input for their Java platform. It’s “true”, graphics are used as data buffers rendered to the graphics card output throughout various call-backs, such as RenderedImage’s or VolatileImage’s. Indeed OpenGL buffers provided the most of soft- and hard-ware acceleration for high-end graphics.
BUT the problem arises when the native librairies don’t load on all system’s or have to be disabled (e.g. the JAI codecsLib is disabled for Windows) or the System graphics layer are system-dependent (e.g. Apple’s Quartz or M’soft DirectX or the open library OpenGL). Sun Java dev’s released their Java 6th edition to provide more compatibility with the recent graphics cards buffers and routines, which has still some enhancements to be made till 7th edition.
One of the more accessible solution is to convert RenderedImage to VolatileImage instances to enter up into the VRAM buffers. Heading to this way, we face an uneasy situation where the VolatileImage is known to be instanciated OPAQUE. Now how to provide the same TRANSPARENCY and easiness of the RenderedImage’s ?? The solution has become real (since 5th edition )with the VolatileImage TRANSLUCENT parameter. Well, this is not sufficient, the background of VolatileImage is still filled with some WHITE-COLOR that renders opaque. So here’s the way to render ALL YOUR VOLATILE IMAGES W/ FULL TRANSPARENCY AS BACKGROUND :
/**
* Instances a new VolatileImage from an image object.
* @param size dimensions
* @return VolatileImage created
* @see java.awt.image.VolatileImage
*/
public static VolatileImage createVolatileImage(Dimension size) {
VolatileImage vdata = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().createCompatibleVolatileImage(size.width, size.height, VolatileImage.TRANSLUCENT);
Graphics2D g = vdata.createGraphics();
Composite cps = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, 0.0f));
g.fillRect(0,0, size.width, size.height);
g.setComposite(cps);
return vdata;
}
As you can see, the VolatileImage is given the TRANSLUCENT parameter and then Graphics are realized once to fill them with the AlphaComposite DST_IN and the alpha value to a floating zero. THIS CHANGES A LOT THE RENDERING SPEED.
: : :
EDIT : it should be reset back to the default Composite, which must be opaque SRC_OVER.