Available Video-Modes Selection Dialog (LWJGL)

Hia, I’m working on something bigger (as always) but I figured this deserved it’s own little spot here.

This code will popup a small window in the middle of the screen, where the user is asked to select resolution, refresh rate, color depth etc information. It is very easy to use this in your own code. Also, you can pass a list of preffered values for resolution etc, the dialog box will attempt to select the preferred values. Also, when selecting a different resolution, only the color depths and refresh rates available for that resolution will be present in the list.

http://cal007300.student.utwente.nl/vincent/resolutiondialog.jpg

You can use it like this:


if(ResolutionDialog.presentDialog("Choose Video Options") == ResolutionDialog.DIALOG_BUTTON_EXIT) {
	System.exit(0);
}
		
try {
	fullscreen = ResolutionDialog.selectedFullScreenValue;
	Display.setDisplayMode(ResolutionDialog.selectedDisplayMode);
	screenWidth = ResolutionDialog.selectedDisplayMode.getWidth();
	screenHeight = ResolutionDialog.selectedDisplayMode.getHeight();
	Display.setTitle(GAME_TITLE);
	Display.setFullscreen(fullscreen);
	Display.setVSyncEnabled(true);
	Display.create(new PixelFormat(0,16,0,ResolutionDialog.selectedAntiAliasMode));
} catch (Exception e) {
	e.printStackTrace(System.err);
	Sys.alert(GAME_TITLE + " - Error", "Unable to initialize display.");
	System.exit(0);
}

Enjoy, I hope it is usefull to you. Also, if you find errors, have improvements or just love it etc… please comment :slight_smile:

Regards,

  • Vincent

It could be very handy. I’ve never have time to do this properly myself, so, thanks!

hehe, A few years back I made something very similar (though for Java2D, not LWJGL)

http://www.pkl.net/~rsc/DisplayModeDialog.jar

this is very useful code, extremly handy and time saving, i might use this. thx for sharing.