Color Alpha slow ? =/

I’m rendering


g.setColor(new Color (0.0f,0.0f,0.0f,floatvalue));
g.drawString(""+somevalue,someposition,someposition);

a 100 times per frame.

it seems that rendering text using drawstring is kinda slow when its that much
and the alpha translucent thing also makes it much more slow

so that a 100 of them can drain the fps to like 40

for understanding purposes: these are damage numbers, like hit points, which are dissapearing after time

You can write the (10 digits * alpha levels) to an image.


0 1 2 3 4 5 6 7 8 9
|
| opaque to fully transparant
|
v
0 1 2 3 4 5 6 7 8 9

Then use g.drawImage(Image, [8 int arguments], ImageObserver) for every digit.

I’m not sure Java2D can multiply an image with an alpha value, so the above allows you to precalculate it.

ah I’m not really sure if I tried that yet. But I knew of this option and naturally I assumed text would be faster than images

Drawing text is done very accurately. On recent jvm versions it even uses sub-pixel rendering, so it’s going to be way slower than Riven’s intermediate image method.

If you didn’t want to do that though, you might be able to speed the text rendering up by using graphics hints. See RenderingHints (http://java.sun.com/j2se/1.4.2/docs/api/java/awt/RenderingHints.html).

Maybe VALUE_TEXT_ANTIALIAS_OFF will help?

EDIT:

By the way, are you using an image as a back buffer? Normally you would draw your shapes, images and text to a back image, then just draw that image to the screen. Image to screen blits have the slowest performance when using java2d, so you don’t want to call g.drawString(…) straight onto the screen.

Ah those RenderingHints. No I tried just know again, they dont seem to do anything at all in my case =D
not even those VALUE_RENDER_SPEED and VALUE_RENDER_QUALITY

Honestly, I’m not sure, I wrote this double buffering thing long ago and then added BufferStrategy to it.


Graphics2D gg = null;
...
gg = DisplayMan.getGraphics();
      		
gg.setColor (getBackground ());
gg.fillRect (0, 0, this.getSize().width, this.getSize().height);
gg.setColor (getForeground());

renderAllKindsofShit (gg);

gg.dispose();

try
{
	DisplayMan.getStrategy().show();
}
catch(Exception e){}

Thats basically my rendering process =0

well the problem is still there but I reduced the possible amount of text things to 30

and also, I was really shocked: I used more heap size occasionally and stuff, but then I realized that my game would sometimes slow down to 52 fps in the action with no bigger heap size, and if I would explicit use a big heap size it would never slow down.
kinda strange… but has to be logical, I guess =P