Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (804)
Games in Android Showcase (239)
games submitted by our members
Games in WIP (868)
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  
  BufferStrategy  (Read 44387 times)
0 Members and 1 Guest are viewing this topic.
Offline Pyrodragoon

Junior Devvie


Exp: 14 years



« Posted 2016-05-11 12:35:22 »

Hi there.

I use the following code for entering fullscreen mode via visible=true and exiting the game with visible=false
My problem is, that it doesn't exit but rather leaves a white screen that doesn't react to anything else than killing it with the taskmanager from windows.
Any suggestions on how to solve this ?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
public void showMe(boolean visible) {
      if(visible){
         setIgnoreRepaint(true);
         setUndecorated(true);
         device.setFullScreenWindow(this);
         int depth = device.getDisplayMode().getBitDepth();
         int refresh = device.getDisplayMode().getRefreshRate();
         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
         gg.setFrameSize(d);
         try{
            device.setDisplayMode(new DisplayMode(d.width, d.height, depth, refresh));
            createBufferStrategy(numJavaFullScreenBuffers);
            bufferStrategy = getBufferStrategy();
         }catch(Exception e){
            e.printStackTrace();
         }
         requestFocus();
      }else{
         device.setFullScreenWindow(null);
         setVisible(false);
                        System.exit(0);
      }
   }



Thanks for any help, I appreciate it.
Offline PlainBug
« Reply #1 - Posted 2016-05-11 14:26:20 »

I suppose
1  
device.setFullScreenWindow(null);
throws an exception here. You should debug the code and find out whether
1  
System.exit(0);
is called or not.

By the way, what's the class of device?

Offline Pyrodragoon

Junior Devvie


Exp: 14 years



« Reply #2 - Posted 2016-05-11 16:07:15 »

The class of device is GraphicsDevice obtained from
1  
2  
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = env.getDefaultScreenDevice();

and I'm using this inside a subclass of java.awt.Frame.

And you're right, the first command throws an Exception.

Should I replace
1  
2  
 
device.setFullScreenWindow(null);


with
1  
2  
 
device.setFullScreenWindow(displayMode);
where displayMode is obtained from the device before going into fullscreenmode ?
This works in closing the window now, but the program still doesn't finish.
I get the following console output:
Quote
Mai 11, 2016 6:04:29 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline PlainBug
« Reply #3 - Posted 2016-05-11 19:36:50 »

And you're right, the first command throws an Exception.
Well, it would be very interesting, what the Exception says  Huh
And you could check wether device is null or not.

Should I replace
1  
2  
 
device.setFullScreenWindow(null);


with
1  
2  
 
device.setFullScreenWindow(displayMode);
where displayMode is obtained from the device before going into fullscreenmode ?

Have a look at the API. I suppose setFullScreenWindow(null); is the right decision.
You should probably also read this Tutorial about the Full-Screen Exclusive Mode.

Offline Pyrodragoon

Junior Devvie


Exp: 14 years



« Reply #4 - Posted 2016-05-11 20:58:21 »

I'm sorry, I should've written that as well.

With
1  
device.setFullScreenWindow(null);

I get the following exception:
Quote
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid display mode
   at sun.awt.Win32GraphicsDevice.setDisplayMode(Unknown Source)
   at Game.Graphics.GraphicsEngine.showMe(GraphicsEngine.java:132)


As for the device it's definitly not null. Debug inspection says, it's a
Quote
D3DGraphicsDevice[screen=0]


I read the tutorial you mentioned a few years ago already, which led to my previous code.
In the past I didn't run into those kind of problems.
Some years have gone by without me using the fullscreen exclusive mode.
I'll go over the tutorial again tomorrow, to see if anything's got changed or updated.

Thank you for your help.
I'm a bit confused right now  Wink
Offline Pyrodragoon

Junior Devvie


Exp: 14 years



« Reply #5 - Posted 2016-05-12 13:39:19 »

Now this isn't funny anymore....
I compiled and run the DisplayModeTest from
https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/extra/fullscreen/examples/DisplayModeTest.java
and it doesn't exit either.
The fullscreenmode seems to be exited but there's still a frameicon in my taskbar and I
have something like an invisible or transparent frame above my eclipse which takes no inputs.
Really awkward. Clueless

Maybe I should add something about my environment here:

Windows 7 Home Premium
Java 8 Update 91 (Build 1.8.0_91-b14)
Eclipse Version: Luna Service Release 2 (4.4.2)

on a Phenom II  X4, 8GB RAM, NVidia 465 GTX

Something else I should post in addition ?
Offline PlainBug
« Reply #6 - Posted 2016-05-12 19:15:13 »

Okay this is really not funny anymore Cheesy The DisplayModeTest works well here.

My suggestion is to remove whole java, eclipse, ... and then reinstall everything.

Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2016-05-12 20:53:09 »

Never ever do this:
1  
device.setDisplayMode(new DisplayMode(d.width, d.height, depth, refresh));


Java AWT just cannot cope with your own DisplayMode instances. Pick one from the DisplayMode[] reported by your device. Even a completely identical manually created instance will not function well. This has been the case for over a decade, learn from my mistakes. Pointing

It might not even be related to the issue you are facing, just fix it anyway Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline SHC
« Reply #8 - Posted 2016-05-13 05:05:00 »

I have this code with me (it's even working in 2016, but originally I wrote it in 2012). http://pastebin.com/TABWDFUE

Ask me if you have any questions regarding it.

Offline Riven
Administrator

« JGO Overlord »


Medals: 1371
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2016-05-13 05:22:55 »

I have this code with me (it's even working in 2016, but originally I wrote it in 2012). http://pastebin.com/TABWDFUE

Ask me if you have any questions regarding it.

You have 3 bugs in that code:
 1. You check for a displaymode with 32 bit color depth, as opposed to the color depth of the current displaymode. Just use device.getDisplayMode() as a reference, or use it directly. No need to mess with Toolkit.
2. You 'center' the mouse by dividing width and height by... four.
3. You set the displaymode N times in rapid succession when there are N displaymodes with the same width, height and bit-depth, but different refreshrates. N is likely to be >= 4

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #10 - Posted 2016-05-13 05:39:53 »

Eagle eyes! I knew there were some bugs, but this was written in the early days when I started programming. This is already dead code, I'm not going to use it again. Just posted here so something would be helpful to the OP.

But you were awesome Riven, it is a great find.

Offline Pyrodragoon

Junior Devvie


Exp: 14 years



« Reply #11 - Posted 2016-05-13 07:59:18 »

Never ever do this:
1  
device.setDisplayMode(new DisplayMode(d.width, d.height, depth, refresh));


Java AWT just cannot cope with your own DisplayMode instances. Pick one from the DisplayMode[] reported by your device. Even a completely identical manually created instance will not function well. This has been the case for over a decade, learn from my mistakes. Pointing

It might not even be related to the issue you are facing, just fix it anyway Smiley

I fixed it. Thanks a lot.
Every suggestion to correct or optimize my code means a lot to me as I'm currently learning a lot of new stuff and trying to make a project
not as quick and dirty as before but rather elaborate.

Quote
Okay this is really not funny anymore Cheesy The DisplayModeTest works well here.

My suggestion is to remove whole java, eclipse, ... and then reinstall everything.

I reinstalled the newest version of both and it didn't have any effect on the outcome.
But it's not bad to have eclipse mars instead of luna now  Wink

Quote
I have this code with me (it's even working in 2016, but originally I wrote it in 2012). http://pastebin.com/TABWDFUE

Ask me if you have any questions regarding it.

And I had a look at your code, updating my frameclass as much as possible including Rivens corrections.

But the result for my own as well as Oracles tutorial class is still the same, a fully transparent frame which is only removeable by killing the process the hard way.
Offline Glabay
« Reply #12 - Posted 2016-06-11 13:09:49 »

How many Monitors are you running on? The Oracle code is not suitable for more than 1 monitor

PI * 13.37 = 42
There are 10 kinds of people; those who know Binary and those who don't
Why programmers confuse Christmas and Halloween; Because 31 OCT = 25 DEC.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (581 views)
2019-09-04 15:33:17

hadezbladez (5510 views)
2018-11-16 13:46:03

hadezbladez (2402 views)
2018-11-16 13:41:33

hadezbladez (5772 views)
2018-11-16 13:35:35

hadezbladez (1223 views)
2018-11-16 13:32:03

EgonOlsen (4661 views)
2018-06-10 19:43:48

EgonOlsen (5682 views)
2018-06-10 19:43:44

EgonOlsen (3198 views)
2018-06-10 19:43:20

DesertCoockie (4095 views)
2018-05-13 18:23:11

nelsongames (5115 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08
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!