Error when trying settings.setBitsPerPixel(); with .setFullScreen()

I trying to this tutorial i found error
http://wiki.jmonkeyengine.org/doku.php/jme3:intermediate:appsettings

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

Try:

modes[i].isFullscreenCapable()

before setFullscreen.

Thanks’s for replying

I don’t know… But when i copy your code there is error :

cannot find symbol
    symbol : method isFullscreenCapable()
    location : class DisplayMode
----
(Alt-Enter shows hints)

I do a search with your code but there is no method ?

http://wiki.jmonkeyengine.org/doku.php/documentation?do=search&id=isFullscreenCapable

Hi,

Do use the following classes?

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

Hi Recon ! Thank’s for replying…

I got error when trying your code

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…

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

i still can’t use .setFullScreen() with .setBitsPerPixel() yet…

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();

It Kecon >_<
Sorry i missed it…

I try your code but display.display modes doesn’t getRefreshRate and getBitDepth so i change it to getFrequency and getBitsPerPixel

         app.setShowSettings(false);
         AppSettings settings = new AppSettings(true);
         final DisplayMode[] modes = Display.getAvailableDisplayModes();
         int i = 0;
         settings.setResolution(modes[i].getWidth(), modes[i].getHeight());
         settings.setFrequency(modes[i].getFrequency());
         settings.setBitsPerPixel(modes[i].getBitsPerPixel());
         boolean fullscreenCapable = modes[i].isFullscreenCapable();
         if (fullscreenCapable == true) {
         settings.setFullscreen(true);
         }
         settings.put("Title", "My awesome Game");
         app.setSettings(settings);

Yep… Like syntax above ?

The game was fullScreen now… However i still don’t know how to solve the problem with my GraphicsEnvironment syntax…

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. :smile:

Not sure what you want to do more with GraphicsEnvironment though. I don’t think it should be needed.