Display modes?

Hey guys? I want to let user to change the display mode(resolution, bit rate, color depth) in game, and for this i must get all possible display modes…Is there a method witch return an array of display modes?

Here you go:

[java]

GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

DisplayMode modes[] = device.getDisplayModes();

for (int i=0; i < modes.length; i++){

System.out.println(modes.getHeight() + "," + modes.getWidth() + "," + modes.getBitDepth() + "," + modes.getRefreshRate());

}[/java]

1 Like

what about if i want to choose one of the display modes and set it?

ahh, nvm, silly question, found it… thank you

Glad I could be of help :wink:

actually doesn`t work…

[java]GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

device.setDisplayMode(device.getDisplayModes()[0]);

[/java]

http://hub.jmonkeyengine.org/javadoc/com/jme3/system/AppSettings.html

@pengu, what doesn’t work? My code outputs all the modes supported. Then you must check it yourself:



if modes == x…



and using the AppSettings pspeed gave you.



You can’t expect us to do all your work :wink:

for example i try it like this

[java]GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

java.awt.DisplayMode modes[]=device.getDisplayModes();

for(int i=0;i<modes.length;i++)

{

if(modes.equals(new java.awt.DisplayMode(1280, 960, 32, 60)))

{

settings.setFullscreen(true);

settings.setResolution(modes.getWidth(), modes.getHeight());

settings.setDepthBits(modes.getBitDepth());

settings.setFrequency(modes.getRefreshRate());

break;

}

}[/java]

but i can’t figure what is wrong :frowning:

Try putting in a debug statement and/or breakpoint to make sure that if is getting run…

@pengu said:
for example i try it like this
[java]GraphicsDevice device=GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
java.awt.DisplayMode modes[]=device.getDisplayModes();
for(int i=0;i&lt;modes.length;i++)
{
if(modes.equals(new java.awt.DisplayMode(1280, 960, 32, 60)))
{
settings.setFullscreen(true);
settings.setResolution(modes.getWidth(), modes.getHeight());
settings.setDepthBits(modes.getBitDepth());
settings.setFrequency(modes.getRefreshRate());
break;
}
}[/java]
but i can't figure what is wrong :(


Are you doing this after the app is already initialized? What do you do with the settings object when you are done setting stuff on it?

yes i`m doing this after i start the application…I want to let users to change display mode via game menu.

You have to apply the settings to the app.



Something like app.setSettings(settings);

And you have to make the app restart. http://hub.jmonkeyengine.org/javadoc/com/jme3/app/Application.html#restart()

well, now it work but not if i set 32 bits depth…for example if i do something like this

[java]

if(modes.equals(new java.awt.DisplayMode(1920, 1080, 32, 60)))

{

…set bla bla

}

[/java]

i will get “SEVERE: Failed to set display settings!

org.lwjgl.LWJGLException: Insufficient depth buffer precision”