So for the first time in a few years I tried AWT

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 :wink: )

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:

  1. Why on Earth is anyone actually seriously attempting to use AWT for games? Why did anyone persist?

  2. 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 :slight_smile:

I think you were a little harsh on AWT.

Font rendering is of course going to be slow a game. You don’t render curves etc in Alien Flux. You had to write the blitting version to be fair.

You CAN use transparency with Volatile images if you set a runtime property.

You probably can do some colour modulation with Java2D compositing modes - but you will lose the acceleration I bet so you are right on that one.

Why construct a new Color object all the time for fading out particles? Make an array of Colors. Or are these particles randomly colored AND they need to fade out? If so, can you use the compositing modes to adjust the alpha when blitting to fade out the particles?

Of course I still wouldn’t expect AWT to come close to coding directly with OpenGL. There is a reason for JOGL and LWJGL of course.

BTW I think round for was supposed to go to AWT :slight_smile:

The answer on differences in fullscreen is because you are using the OGL driver. AWT is going through DX and usign the DX driver.

If they differ, its the fault of the card manufacturer.

FWIW, I think AWT is OK for making not too demanding 2d stuff. In fact its performance even surprised me sometimes, but maybe that was because of my expectations :wink: (awt has gone a long way since 1.1 applets so my expectations weren’t very high). OTOH, I probably won’t use it anymore for games (except maybe for texture loading and stuff) because openGL gives me more access to eyecandy, LWJGL ‘just works’ and awt these days involves a lot of fiddling with runtime props and such to get it to perform and even then it seems to behave differently on different platforms.
It seems to be struggling between being performant and meeting the java goals and it succeeds only partly with both.

[quote]You CAN use transparency with Volatile images if you set a runtime property.
[/quote]
The fact that you can use transparency in awt with a runtime property is nice, but why a runtime property? Why can’t it be enabled by default?

Erik

It’s not the fault of the DX driver in this case at all. All the blending and blitting is getting done in software blit routines written in Java and it just isn’t fast :confused:

It’s very hard, with a straight face, to say that AWT is ok-ish for simple 2D stuff, when I’ve barely managed to draw a background and blend a few bits of text onto it before the framerate plummeted.

What’s that flag to allow 8-bit alpha in AWT again? I’d like to try it again to see if I can get all my rendering into VolatileImages, which are in theory just as fast as OpenGL manages.

(Round 4 corrected ;))

More and more I wonder why the AWT isn’t deprecated and replaced with AWT2.0 which closely follows the driver APIs underneath it. (I don’t think SWT is the way forward, unless it gets a whole load easier to use)

Cas :slight_smile:

System.setProperty(“sun.java2d.translaccel”, “true”);

[quote][…]
The fact that you can use transparency in awt with a runtime property is nice, but why a runtime property? Why can’t it be enabled by default?
[/quote]
It wasn’t tested that well… however they decided to make it accessable via properties in order to let freaks like us play with it :slight_smile:

IIRC there is/was at least one strange bug with drawLine if it’s enabled.

Gradient paint… I was kinda surprised, that you didn’t mentioned it’s slowness. Also that comparison was imo a bit biased and unfair, because most of the stuff you mentioned is absolutly untypical for a 2D game.

99.95% of the commercial 2D games doesnt use transparency at all. The hardware doesn’t even support it in most cases. For example Mega Drive(Genesis), Saturn and NeoGeo the SNES on the other hand is able to use 8 different “transparency shades”… however it’s rarly used. Only some beat’em ups use it for the shadows… everything else is just bitmask stuff… dithering… flashing.

After all it isn’t that bad. Really :slight_smile:

Oh and I would use MemoryImageSource if I would like to use massive particle effects.

Your numbers about transparency use in games are going to be somewhat skewed by the large amount of GBA games, most of which use transparency in one form or another - using it is dead simple, its just a flag or two. The only snag is that theres not a huge range of different blending modes.

But 2D AWT always annoys me in being rather too unreliable. Sure you can use transparency, but as soon as you do you get totally unpredicatable framerates from machine to machine. Likewise with other effects like rotation. At first glance it seems like you’re stuck with Megadrive-like capabilities: fast bliting with 1-bit alpha, no proper transparency, image fliping. But its not even at that level - you can’t scale or shear an image and maintain the speed, you can’t toy with pallets and keep the speed, and you can’t do the simple highlight and shadow effects, and obviously you can’t do those funky effects where you toy with the graphics setup mid-scanline.

My only real gripe with LWJGL/Jogl is that fonts are such a pain.

The thing that really disgruntles me about it all is that “just because” LWJGL has a native DLL (or JOGL for that matter) that the vast majority of Java programmers are going to continue to churn out the same laughable shit that perpetuates Java’s reputation as being a joke in performance terms.

Even those developers with the know-how are extremely reluctant to use LWJGL because they “want to target applets” (why? so you can run a shit looking game inside a shit browser too as well, to make shit squared?). I hear an awful lot of developers are worried about using OpenGL since M$ killed off the out-of-the-box driver support (and fair enough - 35% or so of Windows users don’t have GL drivers, although 90% of them have seriously powerful graphics cards - but the Mac story is very different. And frankly, who cares about Linux right now…) But without an incentive to use GL, why are people going to download drivers?

It’s interesting that, in the goal of crossplatform compatibility, we see developers still producing effectively two versions of their rendering engines, one to cope with how shit MSVM1.1 is and the other to cope with how shit JRE1.4.x is, and still both results are shit. An awful lot of effort goes into especially trying to make things look shit in Java.

Is it possible to use native DLLs from an applet?

Cas :slight_smile:

ps. I didn’t get that flag to do anything useful with transparency. Still 30fps. Yuk. Give up.

Its this tag of “pure java” that people are scared of. I think to use a DLL from an applet you’ll need a certificate. Nice to hear someone out there realising that Linux doesn’t instantly == cool.

All of this aside, wasn’t it you saying just recently that its not really super tip top graphics that make a game, so should it matter that it doesn’t run too fast with super graphics as long as people write games with great game play (like that one “A little hack” in Your Games Here)

Kev

Heh :slight_smile: Now I’ve actually got Linux stats to compare with I know where my money’s going :stuck_out_tongue: Maybe next decade they’ll get their heads out of their arses.

And indeed I did say that it’s gameplay that’s what gives players that special feeling. But gameplay doesn’t count for much if you need a 2GHz processor to render it in software and it still runs at the speed of treacle (which really rather spoils the gameplay for a lot of games). And given the choice of two similar playing games, and one’s got ultra smooth spiffy alpha blended graphics and one’s got cookie-cut or slow-as-sludge, you know which one the punter’s going to buy.

Now when you’re in business writing games, you’re in competition with everyone else. It has been noticed that the bar for production values rises slowly and inexorably along with the abilities of machines. Five years ago you could have just got away with Java’s current performance capabilities in 2D on the hardware of the time - which means what I’m seeing now on 1GHz chips I’d have expected to see running equivalently on a 300MHz Celeron back in 1999. And indeed, look at the indie games out there in 1999 - Dweep Gold springs to mind.

Zog’s rocking trouble is brilliant in its gameplay (and as I said back there, it should be, because it’s fundamentally the same mechanic as my next game minus zapping :P) but if you spruced it up and turned it into a professional production using pure Java, and then tried to pitch it against IotJ, you’d almost certainly be buying IotJ because it would run at a rock steady 60fps with graphics that will hopefully make you want to start taking mushrooms again. At this time I do not consider any pure Java games programmers to be in competition with me (I mean this in a friendly way) because they are so far behind in what they’re capable of delivering using the AWT toolset that the paying consumers just ignore them. I’m competing with Blitz3D and hardened C++ indie games programmers.

Sometimes after ranting I, er, forget what my point was, as has happened in this case…

Cas :slight_smile:

OOI, when we going to be seeing IotJ ?

Kev

[quote]The thing that really disgruntles me about it all is that “just because” LWJGL has a native DLL (or JOGL for that matter) that the vast majority of Java programmers are going to continue to churn out the same laughable shit that perpetuates Java’s reputation as being a joke in performance terms.

Even those developers with the know-how are extremely reluctant to use LWJGL because they “want to target applets” (why? so you can run a shit looking game inside a shit browser too as well, to make shit squared?). I hear an awful lot of developers are worried about using OpenGL since M$ killed off the out-of-the-box driver support (and fair enough - 35% or so of Windows users don’t have GL drivers, although 90% of them have seriously powerful graphics cards - but the Mac story is very different. And frankly, who cares about Linux right now…) But without an incentive to use GL, why are people going to download drivers?

It’s interesting that, in the goal of crossplatform compatibility, we see developers still producing effectively two versions of their rendering engines, one to cope with how shit MSVM1.1 is and the other to cope with how shit JRE1.4.x is, and still both results are shit. An awful lot of effort goes into especially trying to make things look shit in Java.
[/quote]
Besides the fact that I don’t share your opinion about Linux, I think you really should use the word “shit” less often.

lol
it’s only about 3 percent ::slight_smile:

About 7 or 8 months ago I too finally got tired of this predicament. I felt I had finally hit a wall and this time no nasty trick was going to get me though it, or round it, over it or under it.

I suppose what really gnaws at whats left of my soul at night is that you are so close to a group of tangibly good instruction that might just might get you out of the mess your in but you know what. They’re forever out of reach. I was thinking MMX.

Yes folks, I admit it I once learned machine code and liked it. In fact it bit me so hard its difficult to forget, no matter how good compilers get or how easy Java is some times or even the fact that if you get it wrong it’ll run slower on the next generation of CPUs.

So late at night, when one of the b*stard neighbours staggers in at 5am and decides “Hey, this is a good time to party” and promptly put the worst piece of music (or should that be muzak) you have ever heard at full volume, I get attacks of “what ifs…”…

I sure you all get them, and as you know a “what if” is hard to live with.

My what if is/was called Troll Fluff.
High Rez timer
EXACT CPU clock cycle counting
Direct Input Keyboard.
Direct Input Wheelie mouse.
Direct Audio for ultra low latency and click free sound.
Hardware V-Sync (at last proper arcade action)
Lets you know the Mhz rating of the CPU you are using.
(all that lot works)

The intention was to release it as Open Source, but still it lays un touched and un finished on my hard drive. Its compilable with MinGW too (against DX7).

“So what” I hear you cry, most of this can be done in various shades of bad with the latest greatest Java.

Well, me being me, decided that I’d make the effort to get it to work in as many JVM’s as possible:
IBM 1.3
SUN 1.3
SUN 1.4
Symantics 1.1.5 (Thats Netscape 4.73 folks)
Microsofts 1.1.4

Also I’m not so fond of big downloads having a modem, so it was/is a 6K class file and a ~100k .dll.

And it works for Applets live on the web WITHOUT having to use a certified JAR file, which makes life a whole lot easier. Only Netscape 4.73 throws up a dialogue box, to which you click on “Grant” and off your go.

Anyway this was just to let Cas know that its quite possible to get an Applet to run with a DLL. In fact I must apologies because I had intended to take a look at the LWJGL library see if I could get it too work as such, but I’m afraid I’ve got lazy and tired of java.

The only mild trouble would be creating an auto installer, as its a bit of a nightmare finding out which version of Java is running and where it is located (Suns java plug in does not help). A Manual install is not very difficult to do, copy 2 files and modify a third (or unzip for MS).

Additional problems, unloading the DLL once the applet has finished (because some JVM’s seem to need the JVM to quit entirely) and the low thread priority in Applets (much lower than Applications) + plus have you seen how many threads & processes Java needs to run, it no surprise its difficult to get something running smooth.

Hope that helps

Woz.
P.S.
Yes I have got a mutilated version of .:Redemption:. running at 60Hz hardware vsync with thumpingly loud music and AT LAST sound effects that go off when they are triggered! Looks great on a telly.

P.P.S.
If you hadn’t noticed Troll Fluff was an attempt to plug some of the (gapping?) holes in Java, that even a 1983 home micro computer would support.
Things like why on earth didn’t they include a blitter function, why stop at System.arraycopy()? an almost entirely useless command if you ask me.

[quote]1. Why on Earth is anyone actually seriously attempting to use AWT for games? Why did anyone persist?

  1. 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.
    [/quote]
    Disclaimer: I don’t write games for a living, but I have a specialization in graphics and have professionally developed graphically-intensive imaging applications.

IMHO, your problems with AWT boil down to the fact that you misunderstand its purpose. AWT is equivalent to Windows’ GDI. Some games get written using GDI - but very few - I’m thinking of things like Solitaire and Pinball. There’s a reason for this - GDI was never designed for high performance games. It was written to be the basis of a windowing system. Tell me, what does AWT stand for? You got it - Abstract Windowing Toolkit. Just like GDI, AWT is also the basis of a windowing system - Swing.

For Java, Sun has not opted to spend the resources to create a equivalent to DirectX. What you and others are doing with LWJGL, and what Yazel and others are doing with Xith3D, is building a “Java DirectX”. Sun is now spending some resources to also help in these efforts with APIs like JOGL and JOAL. In the future, I would love to see Sun establish an endorsed “Java DirectX” that borrows heavily from these efforts - it’s just not here yet.

I look at all of the AWT functionality. like fullscreen and volatile images, as icing on the cake (as well as the beginnings of some primitive cross-platform display support that “Java DirectX” can build upon). I don’t ever believe that AWT alone will evolve to be useful for more than just a handful of gaming applications.

That all said, I’ve been able to use pure AWT to build some simple games I’m putting together for my young child. If everything goes well, I’ll post some JNLP links up here to a few of them later. Perhaps at some point, I’ll even try and make a few dollars from other parents who’d also like to entertain their kids with pretty colors, shapes, and sounds. Aside from horrid performance with alpha blending, AWT seems capable enough to accomplish that.

God bless,
-Toby Reyelts

Seconded both points. A good article doesn’t need such words at all.

As I once said to my prospective mother in law

“I’m happy not to use the words you don’t like, if you’ll not use the words I don’t like. Today, I’ve decided I don’t like the words ‘it’ and ‘and’.”

They are only words after all, used to express a meaning like any other.

I’m interested on this point about Linux also, what is it that you don’t agree with? I think “princec” was saying that there arn’t alot of games players (other than developers) using linux and hence the market isn’t very big.

Kev

[quote]They are only words after all, used to express a meaning like any other.
[/quote]
I don’t tolerate movies with a* and f* and such words in it and so I don’t like to read articles with such words. Isn’t it a common denominator that the forum’s users use official english to communicate, and no pidgin english (u n8 l8 blabla) or French, German, Chinese, … ? Bien que français est une langue magnifique.

[quote]I’m interested on this point about Linux also, what is it that you don’t agree with? I think “princec” was saying that there arn’t alot of games players (other than developers) using linux and hence the market isn’t very big.
[/quote]
Cas wrote: [quote]And frankly, who cares about Linux right now…
[/quote]
Well, I care. I am no regular Linux user yet. Linux is a great platform for developing and working and also for playing if you know howto - improves every version. Several forum users use it. Java’s platform neutrality is a big point and so is SUN’s AWT and general library design.
The Linux user base is increasing constantly and the number will flood when TCPA-Longhorn enters our homes. Many Linux users would be prepared to pay for games if there were good games. Btw Alienflux is not representative for the games market.

Who’s just caring about “game markets” here in the forum anyway? How many full time Java game developers are here? I know Java is ready for games but I also know games are not the only point Java and SUN have care about. Like Toby put it: AWT is something different than a gaming API so why blame if for things it isn’t designed for? Isn’t AWT improving with every iteration?

[quote]I’m interested on this point about Linux also, what is it that you don’t agree with? I think “princec” was saying that there arn’t alot of games players (other than developers) using linux and hence the market isn’t very big.
[/quote]
He said “And frankly, who cares about Linux right now…”. I (and obviously others) care about Linux and use it all the time, so I strongly disagree.
I know he probably wanted to say that the people buying Alien Flux are mostly using Windows and Linux users in general rarely spend money for games. This can be discussed about, but this is simply nowhere in the context of this statement.

Later on in the next post “Now I’ve actually got Linux stats to compare with I know where my money’s going. Maybe next decade they’ll get their heads out of their arses.”

Isn’t this extremely offensive?

You can find similar offensive statements about developers using AWT/Applets (“churn out the same laughable shit that perpetuates Java’s reputation as being a joke in performance terms” and “so you can run a shit looking game inside a shit browser too as well, to make shit squared?”). I don’t even develop Applets, but that’s a bit too harsh.