2

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.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
brickBreaker
  • 339
  • 2
  • 10
  • 2
    Eww. Don't pause. Skip and interpolate. –  Aug 16 '12 at 00:52
  • would you mind giving me a keyword to search for? never heard about this - guess that happens, when you learn java in school.. – brickBreaker Aug 17 '12 at 18:03
  • Generally the delta is not used to determine the paused, but rather how much to update the model. Of course this doesn't always work (e.g. DVD/movie playback needs very precise drawing times or people get irritated about uneven frames), but for games, especially with "non discreet" movement, one way to slow down the FPS, where the FPS is "relative high" (e.g. > 60), is just to "skip" drawing to the next redraw cycle if needed (but don't block the thread). –  Aug 17 '12 at 18:14
  • possible duplicate of [Why does my Java application run so slowly in full-screen mode? (and fine when windowed)](http://stackoverflow.com/questions/8380323/why-does-my-java-application-run-so-slowly-in-full-screen-mode-and-fine-when-w) – DavidS Aug 27 '15 at 22:30

2 Answers2

0

Try setting the system property -Dsun.java2d.d3d=false as suggested here Why does my Java application run so slowly in full-screen mode? (and fine when windowed)

Community
  • 1
  • 1
John Watts
  • 8,717
  • 1
  • 31
  • 35
0

If the above answer doesn't work, then put the window into full screen in a different way.

Instead of:

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if(gd.isFullScreenSupported()) {
    gd.setFullScreenWindow(window);
}

Do this (Assuming you're using a JFrame):

myFrame.setUndecorated(true);
myFrame.setExtendedState(JFrame.MAXIMIZED_BOTH);
BitNinja
  • 1,477
  • 1
  • 19
  • 25
  • The flaw with that is that it does not show your `JFrame` in fullscreen exclusive mode, but rather in windowed mode. It just _looks_ fullscreen. – ThePyroEagle Dec 22 '15 at 16:58
  • @ThePyroEagle Yeah, it's just supposed to be a trick if normal FSEM isn't working – BitNinja Dec 23 '15 at 20:10
  • Even if the system does not support FSEM, setting the window to full screen will still *emulate* fullscreen, so what you really want to check is if the device is headless. – ThePyroEagle Dec 23 '15 at 21:01