sun.java2d.opengl=true in applet with BufferStrategy

Whenever I supply my applet with the parameter -Dsun.java2d.opengl and a value of true, and I use a BufferStrategy for drawing, I get a “dirty” rectangle in my browser. Yet if I run as a JFrame or test applet in Eclipse it works just fine… If I remove the BufferStrategy and just use a off-screen image it works fine but isn’t accelerated…

Any ideas?

TL:DR - I can’t get any of my applets to use both BufferStrategy and sun.java2d.opengl=true simultaneously

Then just don’t use that flag. Java will automatically use hardware acceleration if it is available :slight_smile:

But it doesn’t… There’s definitely a speed increase with the flag.

OK then describe this dirty rectangle effect. Could you show code and/or screenshot?

Try to specify these parameters:

• -Dsun.java2d.opengl=true
• -Dsun.java2d.d3d=false
• -Dsun.java2d.noddraw=true

how can i specify more than one flag in the applet tag?

also: working on getting the examples to show. honestly though, you can write a quick app in a few minutes to demonstrate it. just use the opengl flag in your applet tag, and make the applet use a buffer strategy. it just wont work.

Here’s the browser run:

My engine read out, which does several tests for me to let me know capabilities of surfaces in use, etc.

OpenGL pipeline enabled for default config on screen 0
System information created
Graphics information created
Windows Detected, starting daemon thread
Roguelike Engine v0.0.1
OS: Windows 7 / 6.1 / x86
Java: 1.6.0_31 / 20.6-b01
Security On
startup
Preparing Buffer: Forced Buffer Strategy 
Using Buffer Strategy
Back buffer is Accelerated and Non Volatile
Front buffer is Accelerated and Non Volatile

Here’s it testing in Eclipse, working just fine:

Readout:

System information created
Graphics information created
Windows Detected, starting daemon thread
Roguelike Engine v0.0.1
OS: Windows 7 / 6.1 / amd64
Java: 1.6.0_25 / 20.0-b11
Security Off
Using OpenGL: True
startup
Preparing Buffer: Forced Buffer Strategy 
Using Buffer Strategy
Back buffer is Accelerated and Non Volatile
Front buffer is Accelerated and Non Volatile

Keep in mind all of this works without a buffer strategy no matter what. If i turn the buffer strategy off, it works in jframe as well as in browser but it runs at HALF the speed.
When I test in eclipse, its like 800 FPS, and in browser its like 10 - 30 fps.

After some tests, it looks like the OpenGL backend of Java2D in Windows is sloooow. I don’t get that weird dirty rectangle effect, but it runs at about 40-50FPS.
Direct3D on Windows is fast though, it goes back up to 2000-3000FPS.

;D

So I guess mac users are screwed? You know half of my audience will be mac users.

Nah, OpenGL on Macs and Linux is also fast, my game runs at 500-1000FPS on the MacBook Air.

So do you suggest to just detect OS, and then go down the pipeline accordingly… accelerate transparent images on d3d for windows, and just use open gl for mac.

And then for the applet (since security won’t let us set properties at run time), just write a dx / ogl page and detect os at browser level and redirect to correct page?

Again: don’t set any flags! Java really does automatically detect if hardware acceleration is present. Without any flags, my game still runs at 2000-3000 FPS on my machine and 1000FPS on the Air :slight_smile:

I tried that, and transparent images aren’t accelerated by default… for some reason.

Perhaps I will test more, I am not 100% sure if I was doing things properly when I noticed the problems.

Edit: I need full transparency support (png format) because of roguelike vision. Otherwise, I’ll need two of all things in order to be able to draw dark spots.

Try creating compatible images (line 87). Also look at line 108 for how to transfer an image over from the old Image to the new compatible BufferedImage.

Found this in your code :smiley:


 /**
         * Initializes and displays the window.
         * @param title The title of the window
         * @param width The width of the window
         * @param height The height of the window
         * @param resizable If true, the window will be resizable, else it will not be resizable.
         * @return The JFrame that was initialized by this method.
         */
        protected final JFrame setupFrame(String title, boolean resizable) {
                if(System.getProperty("os.name").startsWith("Win"))
                        System.setProperty("sun.java2d.d3d","true");
                else
                        System.setProperty("sun.java2d.opengl", "true");
                
                final JFrame frame = new JFrame(title);


Hahahahaha I was just experimenting with that a couple days ago XD

For example:

<param name="java_arguments" value="-Dsun.java2d.opengl=true -Dsun.java2d.d3d=false -Dsun.java2d.noddraw=true">

Here is the thread related to your problem.

You don’t really want to turn off OpenGL for all systems though, since it is necessary under Linux and Mac.

Bit-transparent (bitmask) or fully translucent?

This older thread comes to mind:

http://www.java-gaming.org/index.php?topic=19561.5

Trying to support the PNG format fully. In other words, I want to be able to draw 0 - 255 values of alpha.