I like to write old style arcade games but always picked a 800 x 600 resolution as they suited the style. I would try changing the resolution on screen via the program and then playing the game. My own PC copes with this resolution perfectly, my old laptop would lose the bottom part of the screen while my new fancy laptop just lowers the resolution a little and then shows your game in a corner of the screen. I’ve spent the last two days altering the game graphics and mechanics to work at 1080 but the problem hasn’t gone away - it says it’s in 1920 x 1080 but is actually only showing 1450 x 900. If I say getWidth and getHeight then it shows 1920 x 1080 still. I’m baffled.
Is there a simple way of finding out what screen res are actually supported and then picking one that works. The ideal solution for me would be able to set the players screen to 800 x 600 in full screen mode but this seems hellishly difficult. Ideas?
Here’s the code I use :
public static void main(String[] args) {
Frame f = new Frame(device.getDefaultConfiguration());
// get display mode
OldDisplayMode = device.getDisplayMode();
DisplayMode bsf_dm = device.getDisplayMode();
int bsf_scr = -100;
System.out.println("best width="+BestScreenWidth+" height="+BestScreenHeight );
/*
* other stuff
*/
neptune w = new neptune();
f = new Frame("Neptune");
f.setUndecorated(true);
f.setResizable(false);
f.add(w);
Window win = new Window(f);
f.addWindowListener(new FrameListener());
for( DisplayMode dm : device.getDisplayModes() ) {
int scr = 0;
if ( dm.getWidth() == BestScreenWidth ) { scr += 1000; }
if ( dm.getWidth() > BestScreenWidth ) { scr += 40 + (BestScreenWidth-dm.getWidth())/10; }
if ( dm.getHeight() == BestScreenHeight ) { scr += 1400; }
if ( dm.getHeight() > BestScreenHeight ) { scr += 40 + (BestScreenHeight-dm.getHeight())/10; }
scr += dm.getRefreshRate();
if ( dm.getBitDepth() >= 32 ) {
scr += 50;
} else if ( dm.getBitDepth() >= 16 ) {
scr += 25;
}
if ( scr > bsf_scr ) {
System.out.println("Current best width="+dm.getWidth()+" height="+dm.getHeight()+
" dep="+dm.getBitDepth() +" refresh="+dm.getRefreshRate()+
" bitdepth="+dm.getBitDepth()+" scr="+scr );
bsf_scr = scr;
bsf_dm = dm;
if ( dm.getWidth() == ScreenWidth && dm.getHeight() == ScreenHeight ) { break; }
}
}
/*
* try it out
*/
try {
if ( device.isFullScreenSupported() ) {
device.setFullScreenWindow(f);
if ( device.isDisplayChangeSupported() ) {
device.setDisplayMode( bsf_dm );
}
}
} catch ( Exception e ) {
device.setDisplayMode(OldDisplayMode);
device.setFullScreenWindow(win);
}
ScreenWidth = bsf_dm.getWidth();
ScreenHeight = bsf_dm.getHeight();
System.out.println("Chosen width="+ScreenWidth+" height="+ScreenHeight );
w.init();
Thread t2 = new Thread(new WebIO(), "My Thread");
}
The output looks reasonable but the screen res is 1600 x 900:
C:\Users\Mike\Dropbox\Projects\neptune>java -cp ".;neptune.jar;tinysound-1.1.1.jar" -Dsun.java2d.noddraw=true neptune
best width=1920 height=1080
Current best width=320 height=200 dep=32 refresh=40 bitdepth=32 scr=90
Current best width=320 height=200 dep=32 refresh=60 bitdepth=32 scr=110
Current best width=1920 height=1080 dep=32 refresh=40 bitdepth=32 scr=2490
Current best width=1920 height=1080 dep=32 refresh=60 bitdepth=32 scr=2510
Chosen width=1920 height=1080
Aug 11, 2017 11:33:10 AM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.