Recently I came across the fullscreen exclusive mode for Java. As I tried it myself, I encountered something: Rendering the exactly same content in a JFrame or Frame in fullscreen mode takes significantly longer (40 fps), than in an undecorated and maximized window (150-200 fps). My screen is set to 50 fps, that's 20ms per frame and I can't see, where this time is lost. My only idea is, that Jave - for some reason - decides to use my onboard graphicscard while in fullscreen.
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if(gd.isFullScreenSupported()) {
try {
gd.setFullScreenWindow(window);
} finally {
gd.setFullScreenWindow(null);
}
} else {
this.fullscreen = false;
}
I manage repainting with a frame, that trys to hold the frame rate on a certain level by pausing a calculated time.
int delta = (int) (System.currentTimeMillis() - timestamp); //timestamp: start of this round
if(animated - delta > 0)
pause(animated - delta);
And finally I draw on the frame using double buffering:
public void render(Graphics2D a) { //window graphics are passed
Graphics2D g = (Graphics2D) backBuffer.getGraphics();
//Adjusting some rendering hints here...
//Then drawing some stuff...
g.dispose();
a.drawImage(backBuffer, 0, 0, null);
}
That's basically it, and still: the so-called efficient fullscreen mode is damn slow.