Hardware Acceleration in Java applets

Hi!

I have roughly a six-month experince of programming Java and I’m finalizing my first bigger Java applet - a game using Java2D API. I have recently spent some time testing my applet on different computers. I use AffineTransform-class to scale and rotate images. I’m also filling Shapes with Texture paints, taking advantage of double buffering and animating with graphics2d. While testing I noticed my applet doesn’t work well on older computers. Then I got interested in possibilities of making my game run faster.

I’m aware that it’s possible to accelerate Java2D applications and applets with OpenGL. I suppose that enabling OpenGL in my applet
would make it run a lot faster.
I tried to enable OpenGL-rendering by putting the following line into init method:

System.setProperty("sun.java2d.opengl", "True");

And I’m getting

java.security.AccessControlException: access denied (java.util.PropertyPermission sun.java2d.opengl write)

The result is same whether I’m running applet in AppletViewer or in a browser. Is this just a security issue or does it require more advanced knowledge of graphics to enable OpenGL rendering in Java applets using Java2D? If it’s a security issue I’m also eager to hear solutions to that of a problem.

Any responses will be warmly welcomed…

for the applet to permit protected operations to occur properly, there must be a SecurityManager enabled firstly by signing the applet with jarsigner and secondly by sending the JVM a policy.file that grants the required permissions to the signing alias name.
e.g. you would grant

grant { permission java.util.PropertyPermission "*", "read, write", signedBy "yourAliasName"; }

to your alias you use in jarsigner. Then launch appletviewer with this argument line : “-Djava.security.policy=yourPolicyFile” !
See documentations of the jarsigner and policytool tools !
:smiley:

Thanks for tips.

I now signed my applet and when I’m loading the applet browser announces: “The application’s digital signature cannot be verified. Do you want to run the application?”. Proceeding from here, the game starts running. SecurityException doesn’t turn up anymore as I still have the line System.setProperty(“sun.java2d.opengl”, “True”); in my code.

However, the applet runs the same way as before and I can’t see any difference compared with the previous version. So am I missing something here?

Unfortunatly there’s no way to do this at runtime from an applet…

It’s because the graphics pipeline is already set before the applet starts. This is a known issue and I believe the Java2D team mentioned they will fix this.

For applications you can pass the parameter to the jvm, for applets you should specify the Java runtime parameters (you can find these in the Java plugin configuration screen).

Probably not what you where hoping to hear… Of course you could always get the job done using some very dirty approach: Have your signed (configurator) applet modify these system settings and restart the browser (or ask for a restart)… But if you’d go the signed applet route there’s little reason not to use a direct opengl library like LWJGL or JOGL anyways… Though there’s also something to say for sticking to Java2D; It should be more compatible, has more fallbacks (DirectX, OpenGL and software rendering)

The new java plugin coming in 6uN will address this.
You will be able to specify properties for applets.

Dmitri

Good to know, thanks. :slight_smile: