fast java2d translucency
- by mdriesen
I'm trying to draw a bunch of translucent circles on a Swing JComponent. This isn't exactly fast, and I was wondering if there is a way to speed it up. My custom JComponent has the following paintComponent method:
public void paintComponent(Graphics g) {
Rectangle view = g.getClipBounds();
VolatileImage image = createVolatileImage(view.width, view.height);
Graphics2D buffer = image.createGraphics();
// translate to camera location
buffer.translate(-cx, -cy);
// renderables contains all currently visible objects
for(Renderable r : renderables) {
r.paint(buffer);
}
g.drawImage(image.getSnapshot(), view.x, view.y, this);
}
The paint method of my circles is as follows:
public void paint(Graphics2D graphics) {
graphics.setPaint(paint);
graphics.fillOval(x, y, radius, radius);
}
The paint is just an rgba color with a < 255:
Color(int r, int g, int b, int a)
It works fast enough for opaque objects, but is there a simple way to speed this up for translucent ones?