Mixing Swing and Fullscreen exclusive mode

I have a problem i have to solve, I’m drawing in fullscreen exclusive mode, i have 2 setups,
first one i had was that i used two frames, one is the one i draw on and the other is my swing frame. i used to switch between the two, which worked fine, but on certain computers it doesn’t work.

so i changed it to one frame, using a canvas to draw on when i needed i remove it and add a panel with the swing things.
problems with this is, 1. the swing frames seems to not paint certain components untill i move over it. but i do call a repaint and validate on the panel. secondly switching back to the canvas doesn’t draw anything. ANd thirdly, in java 1.6 N my framerate drops to 25fps and i see it’s doing exclusive software rendering, and sometimes i see a hardware rendered call. but JRockit 6 gets the full 60fps, full hardware rendering.

Does anyone have any idea how i can solve this? the code for the second one is http://pastebin.com/m779738fe

It sounds like you’re “almost” using active rendering, which is what you should do for fullscreen exclusive mode. Basically, you have to call paint, not repaint if you have it set to ignore repaint.

I didn’t look at your code though. I’m just guessing.

I am using active rendering, but i actually completely forgot i set it to ignore repaints. I’ll give that a shot and see.

For the reasons too long to explain the new pipeline won’t use HW acceleration
in the following cases:

  • fullscreen mode
  • any kind of heavyweight component added to the frame (like a Canvas)
  • VolatileImage is used as the back-buffer (and copied to the screen)
    instead of BufferStrategy

Another case:

  • if there’s a BufferStrategy created for the frame (like it is by Swing by default)
  • and you use your own VI as back-buffer as well

So you may be running into one of these cases.
(note that Swing may switch to using VI for the back-buffer
when you enter FS mode).

So I’d suggest handle double-buffering yourself: create a BS,
get graphics, drive swing repainting yourself so that it renders
to your BS (you may want to use your RepaintManager for that)

We may relax the first condition mentioned above and allow hw
acceleration if there’s only a single Canvas added to the frame,
but there’s not much that can be done for the second case.

Thanks,
Dmitri

hmm, is that why the latest 6uN release breaks my 3 year old 4k shooter entry? ( horrible source )

It used a VolatileImage as a ‘blurBuffer’ to perform a gradual fade to black.
Sprites intending to be gradually faded were rendered to this intermediary buffer, rather than the BufferStrategy.
Each frame the blur buffer was over-drawn with a fullscreen black 0.13f alpha image, so as to cause the gradual fading.
After this process, the ‘blurBuffer’ was drawn to the bufferstrategy, followed by the normal sprites.

It looks like the fading isn’t taking place at all, so either this isn’t creating what it should :-


(g = (blackImage = gc.createCompatibleImage(SCREEN_WIDTH,SCREEN_HEIGHT,Transparency.TRANSLUCENT)).createGraphics()).setColor(new Color(0.0f,0.0f,0.0f,0.13f));
g.fillRect(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);

Or this isn’t drawing what it should :-

No, that should have worked fine.

What wouldn’t have been accelerated if you copied that VI to the screen.

It is more likely that you’re running into issues because you don’t
validate the VI and BS at all. It’s not guaranteed to work.

Dmitri

ah, so it could be because i’m getting the GraphicsConfiguration from the Frame before I have changed the DisplayMode &| fullscreen.

Presumably that means Component#getGraphicsConfiguration() can return a different object over the life-time of the Component? (the javadoc realy isn’t very clear in this regard)

The VolatileImage class itself seems abit of a design blunder… if it cannot fulfill the specification of it’s super class, Image, then it shouldn’t subclass it.
Alternatively it should throw an Exception indicating said operation(s) are not supported in the Images current state.
Failing silently is horrible horrible behaviour =(

Presumably that means Component#getGraphicsConfiguration() can return a different object over the life-time of the Component? (the javadoc realy isn’t very clear in this regard)

Yes. It happens, for example, when you move a window from one screen to another.
In your case it happens because you change the DM to a different depth.

I don’t know about blunder. The API specifies what you need to do.

Dmitri

Hi, thanks for the reply earlier, iw as expecting to get an email when someone replied, but didn’t happen. lol. i solved the problem for the most part. however, today i suddenly get

6 [W] GetFlagValues: DDraw screen locking is disabled (W2K, XP+)
7 [I] InitDirectX
8 [V] CheckRegistry: Found Display Device 0: NVIDIA GeForce 8800 GT
9 [V] CheckRegistry: Found Display Device 1: NVIDIA GeForce 8800 GT
10 [I] CreateDevice: lpGUID=0xc5d1b8 hMon=0x10001
11 [I] DDSetupDevice
12 [I] DDraw::CreateDDPrimarySurface: back-buffers=0
13 [V] DDSetupDevice: successfully created primary surface
14 [V] DDSetupDevice: successfully setup ddraw device
15 [I] CreateDevice: lpGUID=0xc5d1b8 hMon=0x10003
16 [I] DDSetupDevice
17 [I] DDraw::CreateDDPrimarySurface: back-buffers=0
18 [V] DDSetupDevice: successfully created primary surface
19 [V] DDSetupDevice: successfully setup ddraw device
20 [ Core ] Discovered 23 files.
21 [ Core ] Checkpoint 1
22 [I] DDSetupDevice
23 [I] DDraw::CreateDDPrimarySurface: back-buffers=1
24 [V] DDSetupDevice: successfully created primary surface
25 [V] DDSetupDevice: successfully setup ddraw device
26 [I] D3DContext::D3DContext
27 [V] D3DUtils_SelectDeviceGUID: using TNL rasterizer
28 [I] D3DContext::CreateD3DDevice
29 [E] CreateD3DDevice: bad hardware found, disabling d3d for all devices.

You’re running 6u3/4, not 6uN. Could it be that you’ve (auto?) updated
to 6u4 and it is now the default runtime for you?

Thanks,
Dmitri

That is quite possible, but the though i said i, i was talkin about a team mate, so i can’t know for sure :stuck_out_tongue:

though i hate to see it, but the swing components have been fixed (yay). i’m now able to get in and out of fullscreen mode when needed, because i’m properly handling the bufferedStrategy :).

also seems to perform better now, go figure…

I tink the fullscreen exclusive mode tutorial/examples on sun’s site need to be updated. showing the proper way to handle lost content of the buffers will save alot of people alot of hassle i think…

heh… i should stop coding till 5am… upon checking sun’s site again, i see that they do provide a proper example :slight_smile:

The fullscreen tutorial does need to be updated though.
It still uses Window for the fullscreen window, which is
really not recommended. And there’s some other stuff
too.

Dmitri