Search code examples
javafullscreenframe-rate

FPS drops in Fullscreen mode but fine in Window/Applet?


I've been working on a game engine. It can create games in windowed mode, fullscreen mode or applet mode. The FPS is fine in applet mode and windowed mode (gives me 90-120 fps with upto 3000 objects in the map), but in fullscreen mode, it drops to 25-50 fps. Here's the window class.

https://code.google.com/p/game-engine-for-java/source/browse/src/com/gej/core/GWindow.java

Could not find where the problem is. And more over running on windows is fine but on Ubuntu it has this problem. Listing the display modes gave me the bit depth -1 Here's the complete list on my machine.

1600     900     -1
1440     900     -1
1440     900     -1
1280     800     -1
1280     800     -1
1152     864     -1
1024     768     -1
1024     768     -1
1024     768     -1
832      624     -1
800      600     -1
800      600     -1
800      600     -1
800      600     -1
640      480     -1
640      480     -1
640      480     -1
640      480     -1
720      400     -1

I've found that bit depth -1 indicates BIT_DEPTH_MULTI, a constant in the DisplayMode class. So setting the mode increased the fps to 60-70fps but still not as much as in windowed mode.


Solution

  • Is Java2D using hardware acceleration at all on Ubuntu? Take a look at some Java 2d flags, especially at those that turn OpenGL on.

    On Windows, Direct3D acceleration is used by default. On Linux, you don't get OpenGL by default so try turning it on by using command line option -Dsun.java2d.opengl=true when starting the JVM.