I thought, for fun tonight, because I’m miserable with my lot in life, that I’d try seeing just how far AWT has come in the last few years for games graphics.
Last time I even looked at the java.awt.* package I think was about 2000 or so, and at the time, I shook my head and walked away, shortly afterwards to create JGLIB and then start on the LWJGL.
Here are my experiences:
The screenmode API, though ever so slightly more complicated than the LWJGL, seems ok and reasonably well thought out. Spent half an hour trying to change screen mode without an exception occurring when I thought to actually try using a mode returned from getScreenModes() (just like the LWJGL, by coincidence). So why can I construct a ScreenMode that is identical in every way to one of these modes that doesn’t bloody work? Well, never mind. Round 1 to LWJGL for working reliably, throwing Exceptions when it doesn’t do what it’s expected to do, and being a bit easier to use.
Next up: think of a game. Ok, Lunar Lander.
10 minutes later there is a double buffered fullscreen 800x600x32x60Hz display up, with a nice landscape on it with gradient paint. That was nice. Very easy to accomplish. Renders at 60fps. All well and good. Slightly easier than the same task in LWJGL, which would involve rendering-to-non-rectangular-textures or glDrawPixels shenanigans. Round 2 to AWT.
Create a particle engine and plug it in, just for kicks. Particles bounce off the ground and fade nicely using alpha. I note the huge number of Color objects I’m creating because Colors are immutable and to interpolate between them I need to construct a new one - for each bloody particle, every frame. Duh. So I never get 100% smooth frame rates even when drawing as few as 60 particles on the background. Round 3 to LWJGL for letting you write your own stuff to be smooth.
FPS counter. 30 seconds of typing, and it’s in, in antialised text to 2 dp. Nice. Easy. Far easier than LWJGL. Round 4 to AWT.
Keyboard and mouse input. Have to implement no less than 3 interfaces to get keyboard and mouse input polling working. What it behaves like on a slower single processor system when the rendering thread gets busy I have no idea, but I’m not expecting it to be as good as DirectX. Round 5 to LWJGL, for being comprehensively simpler and 100% reliable (ahah, except on MacOS )
Special effects time. I want to render fancy text labels that fade from one colour to another and float around the screen. You’ve seen this effect before in Alien Flux. Attempt #1 sees me turning on text antialiasing and rendering Impact-PLAIN-18 directly to the window. 1 word is fine. More than one word and the frame rate plummets. With about 60 different ARSE being rendered (ARSE is a great word to render in red) and fading out, I’m getting <20fps, using the server VM, all sorts of clever memory tuning, and dual 1GHz processors on a Radeon 8500. Useless! Ok, fair enough, text rendering like this is possibly not so fast whatever, so I prerender the text (can’t figure out how to colour modulate it now though so fading is out) and blit it instead. Result? 30fps when a few bits of text is on the screen. Oh dear.
That’s just utterly sucky. Round 6 to LWJGL. It may be hard to render fonts in the first place but once you’ve done it, it’s incredibly fast.
I tried Volatile Images, which are complex and difficult to use at best, and don’t have proper alpha transparency - so they can’t be used anyway. I tried createCompatibleImage(), I tried BufferedImage.TYPE_INT_ARGB. I tried many permutations in all but none of them got me anywhere. With everything being blitted in software finally I ended up on 15-20fps which I think is about quarter the speed a C++ programmer would achieve with software blitting.
I’ve given up already before I even bother with the rest of the sprites for Lunar Lander. If it can barely render a few bits of text, 100 dots and the background at 30fps on a fast computer why bother with it?
Now this brings me to a couple of questions about Java games programmers the world over:
-
Why on Earth is anyone actually seriously attempting to use AWT for games? Why did anyone persist?
-
Why on Earth is AWT still quite this slow anyway? I mean, I’m sure it’d be pretty fast if I could get 8-bit alpha in a VolatileImage - but I can’t.
So… I’m sticking with the LWJGL. I see the AWT in a supporting role, generating graphics now and then to give to LWJGL to render.
Cas