[java] What advantages does Java2d have for games?

Started by
8 comments, last by nonnus29 20 years, 5 months ago
Until now I''ve always used plain old java and AWT for my games. From my research I''ve found that Java2d ala 1.4 provides alot of things; 1. Access to full screen modes (on platforms that support it) 2. You can select resolution and color depth in full screen 3. Hardware accelerated blitting via volatile images 4. There is a better timer out there, somewhere (not sure where yet) 5. Alot more image formats supported. 6. BufferImage is WAY better than memoryImageSource The other things I''ve found include alpha blending and rotating of images; although these don''t appear to be accelerated at this time. So am I missing anything?
Advertisement
1) Yes
2) Yes
3) Yes, But buffered images are almost as fasy with none of the drawbacks.
4) No... people have written ( myself included ) timers that can approximate 30fps based on 100% pure java OR you can use of the native libs that provide that functionality.
5) Yes, minimally you can use J2d for it''s image support
6) Yes

If you search under my name ( snowmoon ) here and at javagaming.org you will probably be able to pull up the code I wrote. Unfortunatly I lost most of it in a HD crash. If I were to be starting again today I''de be using lwjgl since it''s lean and fast. There is no upper level functions, but it''s still a great starter.
http://www.gamedev.net/hosted/javanerd/

It''s a 2d library that incorperated my threded timer control.
Snowman, your the prodigal son that has returned. I''ve been using your timer code for a long time and I recently reposted it over at javagaming.org. They have a wiki over there it needs to go on too, but someone must provide hosting for the file. I believe there is a better timer in jdk 1.4.2.b3 or something, I''ll have to research it.

Eh, just use a native timer. You only need the native interface for Windows, all other OSes provide proper resolution. Slap a timer factory front end on, you''re done.

Java2D is generally hardware accelerated under Windows, most of the time BufferedImages are hardware accelerated and if they''re not it''s easy to make them so they are. It is strongly rumored this will also become the case for Linux with 1.5.


Java2D''s major disadvantage is it is so sporadically implemented on all the various platforms. It''s not consistent at all . You can get a program running like butter on Windows and it will be a dismal mess on Linux. I have a paint program I wrote that is 100% unusable on Linux, runs beautifully on Windows. MacOSX? Solaris? I have absolutely no idea what would happen on them. If I use Java2D to any extent, I just declare "Windows only". Which usually means I either don''t use java2d or use it in a modular fashion.
Ok Java2d seems better but i have no idea how it works, and i want to write a game (Sopwith clone) which needs to rotate images, so does anyone know of a good Java2D tuturial? Or maybe a small demonstration program? Thanks..
quote:Original post by tortoise

Java2D''s major disadvantage is it is so sporadically implemented on all the various platforms. It''s not consistent at all . You can get a program running like butter on Windows and it will be a dismal mess on Linux. I have a paint program I wrote that is 100% unusable on Linux, runs beautifully on Windows. MacOSX? Solaris? I have absolutely no idea what would happen on them. If I use Java2D to any extent, I just declare "Windows only". Which usually means I either don''t use java2d or use it in a modular fashion.


If you are interested to know, I run OS X and I can give your app a go and see how things run. In my experience, Java2D on OS X seems to be pretty complete and well done, thanks to Apple''s work on integrating it with the OS.
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
quote:Original post by Anonymous Poster
Ok Java2d seems better but i have no idea how it works, and i want to write a game (Sopwith clone) which needs to rotate images, so does anyone know of a good Java2D tuturial? Or maybe a small demonstration program? Thanks..


Rotating images in real time with Java2D would be difficult, if not impossible. You''d be much better off using OpenGL.

http://java.sun.com/docs/books/tutorial/2d/

looks good. Keep in mind Java2D was meant more for like batch processing and image touch up. Using it in a real time game can be very difficult.

quote:
If you are interested to know, I run OS X and I can give your app a go and see how things run. In my experience, Java2D on OS X seems to be pretty complete and well done, thanks to Apple''s work on integrating it with the OS.


Cool. I''ve got next week off and one thing I''ll be doing is cleaning up all my projects and putting them on my website. I''ll post here when it''s up, right now it''s just sitting in eclipse, hasn''t been "packaged" yet.
quote:Original post by Anonymous Poster
Ok Java2d seems better but i have no idea how it works, and i want to write a game (Sopwith clone) which needs to rotate images, so does anyone know of a good Java2D tuturial? Or maybe a small demonstration program? Thanks..


You can use BufferedImage and the rotation algorithm in this article.

http://www.gamedev.net/reference/programming/features/imageproc/

Per pixel operations like rotation and blending are do-able as long as the image isn''t TOO big.

quote:Original post by nonnus29
Snowman, your the prodigal son that has returned. I''ve been using your timer code for a long time and I recently reposted it over at javagaming.org. They have a wiki over there it needs to go on too, but someone must provide hosting for the file. I believe there is a better timer in jdk 1.4.2.b3 or something, I''ll have to research it.


Yes, bow down before me

It was just a simple solution to the problem. Of course if sun got their act together we would have something better, but us poor game developers always seem to get the shaft.

Biggest problem I had was working out the jitters in my demo. I''m fairly sure it had to do with memory allocation since it was almost 100% reproducable when the free memory jumped.

I''m investigating lwjgl since it''s the most promising at this point.

This topic is closed to new replies.

Advertisement