Possible to get faster FPS with this code?

This is a stripped down version of the code I've been using to run my game. It's basically a 1024x768 frame being run in fullscreen mode and scaled to fit any resolution with some 2d graphics put on top of it. On my machine I get 60 fps just like this, but it drops a lot as soon as I add any images. What kind of fps should I be shooting for and in what ways can I improve this, or should I be using another approach altogether?

import javax.swing.JFrame;

import java.awt.Graphics2D;

import java.awt.Color;

import java.awt.GraphicsDevice;

import java.awt.GraphicsConfiguration;

import java.awt.GraphicsEnvironment;

import java.awt.image.BufferStrategy;

import java.awt.geom.AffineTransform;

publicclass testimplements Runnable{

JFrame mainFrame;

BufferStrategy bufferStrategy;

GraphicsConfiguration gc;

int mouseX, mouseY;

Thread animThread;

Graphics2D g;

AffineTransform a;

double timer;

double frames;

double currentFPS;

double scaleX;

double scaleY;

int gcx, gcy;

public test(GraphicsDevice device){

timer = System.currentTimeMillis();

frames = 0.0;

currentFPS = 0.0;

try{

gc = device.getDefaultConfiguration();

mainFrame =new JFrame(gc);

mainFrame.setUndecorated(true);

mainFrame.setIgnoreRepaint(true);

scaleX = gc.getBounds().getWidth()/1024.0;

scaleY = gc.getBounds().getHeight()/768.0;

a =new AffineTransform();

a.scale(scaleX, scaleY);

gcx = (int) gc.getBounds().getWidth();

gcy = (int) gc.getBounds().getHeight();

mainFrame.setVisible(true);//Keep this in front of .createBufferStrategy()

mainFrame.createBufferStrategy(2);

bufferStrategy = mainFrame.getBufferStrategy();

this.start();

device.setFullScreenWindow(mainFrame);

while(true){

}

}catch (Exception e){e.printStackTrace();}

}

privatevoid render(Graphics2D g){

g.fillRect(0, 0, 1023, 768);

g.setColor(Color.red);

g.drawString(currentFPS+"", 10, 35);

}

publicvoid start(){

if(animThread ==null){

animThread =new Thread(this);

animThread.start();

}

}

publicvoid run(){

while(Thread.currentThread() == animThread){

g = (Graphics2D) bufferStrategy.getDrawGraphics();

if(!(scaleX == 1.0 & scaleY == 1.0)) g.transform(a);

render(g);

g.dispose();

bufferStrategy.show();

frames+=1;

if(frames == 7){

currentFPS = (frames / (System.currentTimeMillis()-timer))*1000.0;

frames = 0;

timer = System.currentTimeMillis();

}

//try {

//animThread.sleep(17);

//} catch (InterruptedException e) {}

}

}

publicstaticvoid main(String[] args){

try{

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

GraphicsDevice device = env.getDefaultScreenDevice();

test gameGraphics =new test(device);

}catch (Exception e){e.printStackTrace();}

System.exit(0);

}

}

Once again, I get about 60 fps with no images and it goes to 15-25 when I put them on. What should I be expecting and can I improve it?

[5806 byte] By [Jasdara] at [2007-11-27 9:43:31]
# 1

I get 85 FPS. I think you get 60 because teh sync option in your driver settings is on, and you have an LCD screen with a vertical frequency of 60Hz :)

with BufferedImage (unaccelerated) your, I get 35FPS.... but I have modified your uneffective code.

1) in void main :

//System.exit(0); //No ! useless..

2)

/*while(true) {

// *NEVER* do that !

}*/

Indeed, the "while true" is heavy consumming, it is useless, there is ALWAYS a way to avoid an infinite empty loop.

You may get more FPS by using VolatileImage.

Kilwcha at 2007-7-12 23:48:57 > top of Java-index,Security,Cryptography...
# 2
I had the exit call because I initially stole the code from somewhere and forgot to take it out... the while(true) was a game update loop that used to be while(!done) but I just needed it to run forever for the example. I ended up deciding to use lwjgl. It runs much faster.
Jasdara at 2007-7-12 23:48:57 > top of Java-index,Security,Cryptography...