SEVERE: Failed to create display
java.lang.RuntimeException: Unable to find fullscreen display mode matching settings
at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:79)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:113)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:744)
If i turn off .setFullScreen() or .setBitsPerPixel() line it work…
// App Setting
app.setShowSettings(false);
AppSettings settings = new AppSettings(true);
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
DisplayMode[] modes = device.getDisplayModes();
int i = 0;
settings.setResolution(modes[i].getWidth(), modes[i].getHeight());
settings.setFrequency(modes[i].getRefreshRate());
// settings.setBitsPerPixel(modes[i].getBitDepth());
settings.setFullscreen(device.isFullScreenSupported());
settings.put("Title", "My awesome Game");
app.setSettings(settings);
I just want to find out what wrong with my code…
Tnx
java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source code - java.awt.DisplayMode is already defined in a single-type import
at mygame.Main.<clinit>(Main.java:17)
I think that .DisplayMode was already been imported by java.awt…
You’re importing DisplayMode twice, but from different packages. They doesn’t contain the same stuff, even if they are called the same. I think you should skip all java.awt.* packages, and you should use org.lwjgl… packages for this instead.
You get all available display modes from Display instead.
final DisplayMode[] modes = Display.getAvailableDisplayModes();
I would probably extract DisplayMode[] modes into DisplayMode mode = modes[0] and would probably do settings.setFullscreen(mode.isFullscreenCapable()); (if is not required)
I suppose this only is for testing, because the first display mode might not be the most suitable in the long run. I would extract graphics settings into a settings file and then dig up the correct resolution from there and only use this code as default. I would probably hard code a resolution when testing. The final product should probably put all these resolutions in a Set (for elemination of duplicates). I suppose that DisplayMode is missing hashCode and equals, so I would make some kind of wrapper class for DisplayMode. I would then add the Set into a List and sort it and finally let the user decide the resolution.
I have however found something odd then going from fullscreen to window mode when not matching desktop’s bits per pixel. It usually crashes, but I’ve not tested around enough to confirm the problem, but that’s another thread!
However your things should work when it comes to check if fullscreen.
Not sure what you want to do more with GraphicsEnvironment though. I don’t think it should be needed.