Need help improving my full screen code.


	private static final DisplayMode[] PreferredModes = new DisplayMode[]{new DisplayMode(800,600,32,0),new DisplayMode(800,600,16,0), new DisplayMode(800,600,8,0)};


private final void FullScreen() {
		final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
		final GraphicsDevice myDevice = env.getDefaultScreenDevice();
		final DisplayMode dm = bestmode(myDevice);

		if(dm == null || !myDevice.isFullScreenSupported()){
			JOptionPane.showMessageDialog(null, Messages.getString("g.36")); //$NON-NLS-1$
			fullScreen = false; //Fall back to window mode.
			return;
		}
		gameWindow.setDone(true); //stops the canvas rendering.
		//this.setVisible(false);
		oldDisplayMode = myDevice.getDisplayMode();
		try {
			myDevice.setFullScreenWindow(this);
			//validate();
			if(myDevice.isDisplayChangeSupported()){ //windows bug fix

				myDevice.setDisplayMode(dm);
				this.setSize(dm.getWidth(), dm.getHeight());// fix for mac os x
				fullScreen = true;
			}
			else{
				myDevice.setFullScreenWindow(null);
				fullScreen = false;
				JOptionPane.showMessageDialog(null, Messages.getString("g.37")); //$NON-NLS-1$
			}
		}catch (final IllegalArgumentException ex) { //Fall back to window mode.
			myDevice.setDisplayMode(oldDisplayMode);
			myDevice.setFullScreenWindow(null);
			fullScreen = false;
			JOptionPane.showMessageDialog(null, Messages.getString("g.38")); //$NON-NLS-1$

		}
		//this.setVisible(true);
		validate();
		pack();
		this.repaint();

		gameWindow.setDone(false);
		gameWindow.setVisible(true);
		new Thread(gameWindow).start();//starts the canvas rendering.
		gameWindow.validate();

	}

Many of my users are unable to use full screen, so I wonder if there can be any improvement on the current code I have.

Also sometimes I see this error when changing to full screen mode. I’m able to get full screen with this error but the game window is blank but not the gui.

[quote]Exception in thread “Thread-8” java.lang.InternalError: Unsupported depth 25
at sun.awt.image.WritableRasterNative.createNativeRaster(Unknown Source)
at sun.java2d.windows.Win32OffScreenSurfaceData.getRaster(Unknown Source)
at sun.java2d.loops.OpaqueCopyAnyToArgb.Blit(Unknown Source)
at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
at sun.java2d.loops.GraphicsPrimitive.convertFrom(Unknown Source)
at sun.java2d.loops.MaskBlit$General.MaskBlit(Unknown Source)
at sun.java2d.loops.Blit$GeneralMaskBlit.Blit(Unknown Source)
at sun.java2d.pipe.DrawImage.blitSurfaceData(Unknown Source)
at sun.java2d.pipe.DrawImage.renderImageCopy(Unknown Source)
at sun.java2d.pipe.DrawImage.copyImage(Unknown Source)
at sun.java2d.pipe.DrawImage.transformImage(Unknown Source)
at sun.java2d.SunGraphics2D.drawImage(Unknown Source)
at GameWindow.render(GameWindow.java:419)
at GameWindow.PaintScreen(GameWindow.java:378)
at GameWindow.myRenderingLoop(GameWindow.java:335)
at GameWindow.run(GameWindow.java:503)
at java.lang.Thread.run(Unknown Source)
[/quote]
If you need more details just post.

Seems I solved my error by adding a wait after I stop the rendering from the game window. My fault there. But Still same problem that many people unable to use full screen. I’ll keep looking.

When full-screen mode isn’t supported, just use a regular JFrame that isn’t full-screen. You can also emulate full-screen mode with a regular JFrame if you make it undecorated and set it’s state to maximized (see JFrame’s documentation for details).

You might also want to allow display modes other than 800x600, but that might involve too much screwing around to make your game look right in other display modes. You would have a similar problem with an undecorated and maximized JFrame as well.

Somehow my reply to this question got lost >:(

Most issues with full screen mode arise from the doing stuff on multiple threads.

You should rearrange your code to execute enter/exit fs/change dm method calls to be on the same thread where you do
your rendering. It could go something like this:


run() {
  while (!done) {
      collectInput();

      handleDisplayChanges();
      
      moveWorld();
      renderWorld();
  }
}
handleDisplayChanges() {
    if (enteringFS) {
     // enter FS or resize window if not fs is not supported
    }
    if (needToChangeDM) {
      // change DM if needed
    }
    // etc
}

Thanks,
Dmitri
Java2D Team

Trembovetski: Thanks, I’ll give that a try.
Fletchergames: Can’t really do that since it’s a null layout, otherwise I would of.

For me that way didn’t work, was getting the error from my first post, but if I close the thread it shouldn’t have any trouble anyway?
Well I don’t see what the problem can be. But at least it doesn’t crash for my users heh.

Solved my problem it seems. Seems I need full permissions for full screen in webstart.
So I’m happy now :wink: