frame rate counter

Hi. I’ve put a frame rate counter in my game and it is giving me an average around 60 fps. This is great but I think that the counter is being limited by my monitor refresh rate (I know I read somewhere that that happens under certain conditions). Is there a way to measure my frame rate without it being limited by the monitor refresh rate? I know that the number would be useless, as the frame rate can’t actually go faster than the monitor refresh rate, but I would still like to see it. Also, I am using System.currentTimeMillis() to get the elapsed time between frames. Is this the best way to measure my game’s frame rate and manage my games timer?

PS
I have no idea how to accelerate my images. I am using BufferedImages, can they be accelerated? Maybe I am already accelerating them. I have my game working at full screen and am using a BufferStrategy to draw. Although there seem to be many informative articles about accelerated images, I haven’t yet seen one which simply and concisely shows how to create and display them. For example, if I have a BufferedImage which I want to draw to the screen, how do I make sure that it is accelerated before I draw it? I think that perhaps I’m missing some important understanding of accelerated images. Some links or an explanation would be great.

http://www.gamelizard.com/JavaGameProgrammingPresentation.htm

Check out my lil’ info packet there. Scroll down and you’ll see that info and more.

Thanks for that link. You’re saying that the GAGETimer will ignore the monitor refresh rate?

As for accelerating images, lets see if I’ve got this right. If I have a BufferedImage “i” which might or might not be accelerated and I want to make an accelerated version called “accelerated”, the following will work?

GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
BufferedImage accelerated = gc.createCompatibleImage(i.getWidth(), i.getHeight(), Transparency.TRANSLUCENT);
Graphics2D accelG = accelerated.createGraphics();
accelG.drawImage(i, 0, 0, null);

And every time I draw “accelerated”, it is, and remains, an accelerated image? How do I check to see if an image is accelerated?

How do I check to see if an image is accelerated?

getCapabilities -> isAccelerated

Oh and don’t be surprised… the default acceleration threshold is 2. That means the image will get only accelerated if it’s drawn twice before.

System.setProperty(“sun.java2d.accthreshold”, “0”);

This way you can set it to 0 - instant acceleration.

That’s wierd. I’m getting a “cannot resolve symbol” error on the getCapabilities(GraphicsConfiguration gc) method. I checked, like, 25 times to make sure I was spelling it right, but no go.

EDIT
Thanks, I have the threshold set to 0.

Seems like that method is 1.5 only. Well… duh…

1.5 is more fun anyways, because you have nanoTime there :wink:

Stupid me. I thought that I was running 1.5. I’ll let you know how it works out after I update.

EDIT
Ha ha … It seems that I had updated the JRE and not the JDK. I guess that would do it.

Ok, I updated and found out that my images ARE accelerated! Thanks for the help with that. I still haven’t put in the timer you suggested, but are you sure that it will ignore the monitor refresh rate? I don’t see how it could avoid it.

Fullscreen+bufferstrat=vsynced

So… add a switch for windowed mode.