I have an app that creates and draws an image on the screen every frame. Every frame a slightly modified image is computed and scrolled slowly across the screen.
If I run the app in a 640x480 window, I see frame rates of 50 fps+.
If I run the app in full-screen mode, I get about 10 fps.
In fullscreen mode: When most of the image is clipped by the screen edges, the frame rate is high and the animation is smooth. As more of the image is visible on the screen the frame rate drops dramatically. This leads me to believe that the bottleneck is the Graphics.drawImage call.
I’ll post some code below to show what I’m doing.
So can anyone suggest ways to speed up the full-screen rendering? Any ideas on why the full-screen rendering is so much slower than the windowed rendering?
Any help would be very appreciated!
Thanks in advance!
Brian.
Code: (edited to keep only the relevant bits and make them understandable)
setup:
window.createBufferStrategy(2);
bufferStrategy = window.getBufferStrategy();
drawImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
imgData = ((DataBufferInt)drawImg.getRaster().getDataBuffer()).getData();
every frame:
drawGraphics = bufferStrategy.getDrawGraphics();
drawGraphics.setColor(backColor);
drawGraphics.fillRect(0, 0, getWidth(), getHeight());
...
int index = 0;
for (int i=0; i < width; i++) {
for (int j=0; j < height; j++) {
int rgb = calculateRGB(i,j);
imgData[index] = rgb;
index++;
}
}
drawGraphics.drawImage(drawImg, x, y, null); // x, y are updated every frame
drawGraphcs.dispose();
bufferStrategy.show();