Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (591)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Need help improving my full screen code.  (Read 2404 times)
0 Members and 1 Guest are viewing this topic.
Offline zammbi

JGO Coder


Medals: 4



« Posted 2008-05-23 06:09:44 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
   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)

If you need more details just post.

Current project - Rename and Sort
Offline zammbi

JGO Coder


Medals: 4



« Reply #1 - Posted 2008-05-24 10:29:17 »

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.

Current project - Rename and Sort
Offline fletchergames

Senior Devvie





« Reply #2 - Posted 2008-05-28 13:59:08 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline trembovetski

Senior Devvie




If only I knew what I'm talking about!


« Reply #3 - Posted 2008-05-28 22:44:44 »

Somehow my reply to this question got lost  Angry

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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
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
Offline zammbi

JGO Coder


Medals: 4



« Reply #4 - Posted 2008-06-01 12:41:30 »

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

Current project - Rename and Sort
Offline zammbi

JGO Coder


Medals: 4



« Reply #5 - Posted 2008-06-01 15:28:25 »

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.

Current project - Rename and Sort
Offline zammbi

JGO Coder


Medals: 4



« Reply #6 - Posted 2008-06-02 11:25:39 »

Solved my problem it seems. Seems I need full permissions for full screen in webstart.
So I'm happy now  Wink

Current project - Rename and Sort
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Gibbo3771 (5 views)
2014-11-24 19:59:16

trollwarrior1 (35 views)
2014-11-22 12:13:56

xFryIx (73 views)
2014-11-13 12:34:49

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (40 views)
2014-11-12 21:09:33

kovacsa (66 views)
2014-11-07 19:57:14

TehJavaDev (70 views)
2014-11-03 22:04:50

BurntPizza (68 views)
2014-11-03 18:54:52

moogie (83 views)
2014-11-03 06:22:04
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!