Default Resolution

Started by bounceWiggleBounce, March 07, 2007, 09:30:50

Previous topic - Next topic

bounceWiggleBounce

Is there any method by which one can get a list of safe resolutions that the application/game can run on?

I was able to create the following method:

public void changeResolution(int resolutionWidth, int resolutionHeight, 
	    int bitDepth) throws ChangeResolutionException {
	try {
	    DisplayMode modes[] = Display.getAvailableDisplayModes();
	    for(DisplayMode currentMode : modes)
	    {
		if(currentMode.getWidth() == resolutionWidth
			&& currentMode.getHeight() == resolutionHeight
			&& currentMode.getBitsPerPixel() == bitDepth)
		{
		    Display.setDisplayMode(currentMode);
		    break;
		}
	    }
	} catch(LWJGLException lWJGLException) {
	    throw new ChangeResolutionException();
	}
    }


As you can see, you can pass just about any int for the resolution width, height and bit-depth. The reason I am asking is because I want to create an options menu where the user can choose a preferred resolution.

Matzon

Display.getAvailableDisplayModes(); gives you all the possible modes.
You could probably filter out some insane modes if you want to, but all of those modes should work with fullscreen

Evil-Devil

If you have enabled "valid resolutions" in your display driver settings "getAvailableDisplayModes()" will return all valid modes your monitor support. Even if the graphic card support much more. Thus aren't listed then.

bounceWiggleBounce

Ah silly me. So will this work?

try {
  DisplayMode modes[] = Display.getAvailableDisplayModes();
  Display.setDisplayMode(modes[0]);
} catch(LWJGLException lWJGLException) {
  // caught exception
}

aldacron

Quote from: bounceWiggleBounce on March 08, 2007, 01:36:09
Ah silly me. So will this work?

try {
  DisplayMode modes[] = Display.getAvailableDisplayModes();
  Display.setDisplayMode(modes[0]);
} catch(LWJGLException lWJGLException) {
  // caught exception
}


With that, you have no idea what modes[0] is. It might be 640x480x16, or it might be something much bigger. What you should do is decide on a sane default, perhaps 1024x768x32 or 800x600x32, and then iterate the list to find a mode that matches.

bounceWiggleBounce

But what if the player's computer doesn't support something sane?
How about this code:

public boolean changeResolution(int resolutionWidth, int resolutionHeight, 
	    int bitDepth) throws ChangeResolutionException {
	try {
	    DisplayMode modes[] = Display.getAvailableDisplayModes();
	    for(DisplayMode currentMode : modes)
	    {
		if(currentMode.getWidth() == resolutionWidth
			&& currentMode.getHeight() == resolutionHeight
			&& currentMode.getBitsPerPixel() == bitDepth)
		{
		    Display.setDisplayMode(currentMode);
		    return true;
		}
	    }
	} catch(LWJGLException lWJGLException) {
	    throw new ChangeResolutionException();
	}
	return false;
}
public void getFirstAvailableResolution() throws ChangeResolutionException {
	try {
	    DisplayMode modes[] = Display.getAvailableDisplayModes();
	    Display.setDisplayMode(modes[0]);
	} catch(LWJGLException lWJGLException) {
	    throw new ChangeResolutionException();
	}
}


And a call to that would look like:

try {
	if(!changeResolution(800, 600, 16))
		getFirstAvailableResolution();
} catch(ChangeResolutionException changeResolutionException) {
	//error
}

rainforest

What happens if the programmers decides to use the current default mode that the computer is operating on?
.:: A journey of thousand miles starts with a single step ::.

bobjob

here is some code that i use

        DisplayMode d[] = Display.getAvailableDisplayModes();
        DisplayMode displayMode = null;
        for (int i = 0; i < d.length; i++) {
            displayMode = d[i];
            //System.out.println(displayMode.toString());
            if (d[i].getWidth() == 640
                && d[i].getHeight() == 480
                && d[i].getBitsPerPixel() == 32) {
                break;
            }
        }
        Display.setDisplayMode(displayMode);


its safe and you can change the values (640, 480, 32)  to a recommended size, if the size isnt supported it will at least be assigned another existing resolution

rainforest

Crisp and works great for me. Thank u very much.
.:: A journey of thousand miles starts with a single step ::.