Problems with Composite

Hi again
I will post the code first and explain then:


	BufferedImage bL;
	Graphics2D bLG;
	double darkness = 155;
	double dd = 0.5;
	private void drawLightsAndNight(Graphics2D g) {
		/*||Created on 23.07.2008 14:32:53||*/
		/*°°°[ composite so that overwrite completely ]°°°*/
		bLG.setComposite(AlphaComposite.Src);
		
		/*°°°[ darkness drawing ]°°°*/
		darkness += dd;
		if(darkness >= 255 || darkness <= 0){
			dd *= -1;
		}
		bLG.setColor(new Color(0,0,0,(int) darkness));
		bLG.fill(bounds);
		
		/*°°°[ lights within darkness ]°°°*/
		bLG.setComposite(AlphaComposite.Src);
		int k = (int) (Math.random()*10);
		int h = (int) (Math.random()*10);
		Ellipse2D.Double el = new Ellipse2D.Double(100-k/2,100-k/2,200+k,200+k);
		bLG.setColor(new Color(255-h,255-h,155+h,25));
		bLG.fill(el);
		
		/*°°°[ go onto screen ]°°°*/
		g.drawImage(bL,0,0,null);
	}

This gives less than 1 FPS…
–> bounds is a Rectangle with size 1280*1024
but that shouldn´t be a problem.

I want to draw some tiles on the screen and
set this image here above so that at night
you see the tiles which are unlightet only behind
a dark “curtain”.
The parts within the lights should be visible.

How can I do this without slowing down so much?
Is there a better way ?
I guess someone here in a gaming forum should already have
much experience with lighting :wink:
Please help me.

Since you are keeping bL why not only redo the calculations if the player moves? Usually you want to reuse the calculations as often as you can.

I could do that with a static Light,
but I want the light to be flickering and that logically not only
when the player moves :wink:

I just don´t understand what Java´s doing there…
I testet the code above for bottlenecks and the only one
is that:


bLG.fill(el);

So filling the BufferedImage with one color slows down so much ?!

Filling a BufferedImage with one color WITH ALPHA is so darmn slow :-…


	private void drawLightsAndNight2(Graphics2D g) {
		/*||Created on 23.07.2008 14:32:53||*/
		/*°°°[ darkness drawing ]°°°*/
		darkness += dd;
		if(darkness >= 255 || darkness <= 0){
			dd *= -1;
		}

		/*°°°[ lights within darkness ]°°°*/
		int k = (int) (Math.random()*10);
		int h = (int) (Math.random()*10);
		Ellipse2D.Double el = new Ellipse2D.Double(100-k/2,100-k/2,200+k,200+k);
		g.setColor(new Color(255-h,255-h,155+h,25));
		g.fill(el);
		
		/*°°°[ draw full bounds without the light ellipse]°°°*/
		Area a = new Area(bounds);
		a.subtract(new Area(el));
		g.setColor(new Color(0,0,0,(int) darkness));
		g.fill(a);
	}

Then how come, that drawing like this the FPS are around 70 ?
Here I fill also nearly the whole screen with an alphacolor
and Area should be slow, too, but isn´t ?!
The only difference is that
g is the graphics object given from the fullscreenmode buffer
where the one above (bLG) was from a BufferedImage offscreen.

The problem is with many lights the solution with java.awt.Area is
really ugly :wink:
And why does something like AlphaComposite exist after all
if it´s to darn slow…