Hi all,
Im trying to use accelerated graphics for my game. I just discovered my VolatileImage were not accelerated. From [1], in the 1.5 API, only OPAQUE images were accelerated. I can’t find any info regarding this with the 1.6 API. Somwhere on your forum, i see that only BufferedImage can be accelerated with transparency, but my code below shows that my BufferImage are never accelerated. My question is simple : how do i get an accelerated transparent image with Transparency.BITMASK on Linux (and, hopefully, all platforms)?
The code below is a small test i wrote while trying to figure out how to do this.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package abricots.test;
import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.ImageCapabilities;
import java.awt.Transparency;
import java.awt.image.VolatileImage;
/**
*
* @author cghislai
*/
public class testAccel {
public testAccel() {
GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.
getLocalGraphicsEnvironment();
for (GraphicsDevice graphicsDevice : graphicsEnvironment.
getScreenDevices()) {
System.out.println("DEVICES : " + graphicsDevice.getIDstring());
System.out.println(" - MEM :" + graphicsDevice.
getAvailableAcceleratedMemory());
System.out.println(" - DISPLAYCHANGE : " + graphicsDevice.
isDisplayChangeSupported());
System.out.println(" - FULLSCREEN : " + graphicsDevice.
isFullScreenSupported());
}
GraphicsDevice graphicsDevice = graphicsEnvironment.
getDefaultScreenDevice();
GraphicsConfiguration graphicsConfiguration = null;
for (GraphicsConfiguration gc : graphicsDevice.getConfigurations()) {
System.out.println("CONFIGURATION : " + gc.toString());
System.out.println(" - BOUNDS :" + gc.getBounds().
getWidth() + " x " + gc.getBounds().
getHeight());
System.out.println(" - BUFFER : FullScreenRequired:" + gc.
getBufferCapabilities().isFullScreenRequired());
System.out.println(" - BUFFER : Multi:" + gc.getBufferCapabilities().
isMultiBufferAvailable());
System.out.println(" - BUFFER : PageFlipping:" + gc.
getBufferCapabilities().isPageFlipping());
System.out.println(" - BUFFER : BackBuffer Accelerated:" + gc.
getBufferCapabilities().getBackBufferCapabilities().
isAccelerated());
System.out.println(" - BUFFER : FrontBuffer Accelerated:" + gc.
getBufferCapabilities().getFrontBufferCapabilities().
isAccelerated());
System.out.println(" - IMAGE : Accelerated:" + gc.
getImageCapabilities().isAccelerated());
System.out.println(" - COLOR MODEL : " + gc.getColorModel().
toString());
if (gc.getBufferCapabilities().isPageFlipping() &&
gc.getBufferCapabilities().
getBackBufferCapabilities().isAccelerated() &&
gc.getBufferCapabilities().
getFrontBufferCapabilities().isAccelerated() &&
gc.getImageCapabilities().isAccelerated() &&
gc.getColorModel(Transparency.BITMASK) != null) {
graphicsConfiguration = gc;
break;
}
}
VolatileImage im = graphicsConfiguration.createCompatibleVolatileImage(
20, 20);
System.out.println("VImage accelerated :" + im.getCapabilities().
isAccelerated());
im = graphicsConfiguration.createCompatibleVolatileImage(
20, 20, Transparency.BITMASK);
System.out.println("tr VImage accelerated :" + im.getCapabilities().
isAccelerated());
ImageCapabilities caps = new ImageCapabilities(true);
try {
im = graphicsConfiguration.createCompatibleVolatileImage(20, 20,
caps,
Transparency.BITMASK);
} catch (AWTException ex) {
System.out.println("Cant create accel VImage");
}
BufferedImage bim = graphicsConfiguration.createCompatibleImage(
20, 20);
System.out.println("BImage accelerated :" + bim.getCapabilities(graphicsConfiguration).
isAccelerated());
bim = graphicsConfiguration.createCompatibleImage(
20, 20, Transparency.BITMASK);
System.out.println("tr BImage accelerated :" + bim.getCapabilities(graphicsConfiguration).
isAccelerated());
}
}
Thanks,
Charly
[1] http://java.sun.com/j2se/1.5.0/docs/guide/2d/new_features.html