Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can Java help me with multiplatform 2D animation?

Status
Not open for further replies.

DoobieSister

Programmer
Oct 20, 2004
6
GB
I am considering writing a 2D graphics intensive animation program like Creatoon ( or Moho ( hopefully using OpenGL, and I need it to work across Windows, Mac and Linux.

With the current state of Java, can I really write it on Windows and it will just work on the other platforms?

Also, what are the speed issues? Will it run too slowly?

If Java is suitable, what libraries can people recommend? This won't be open source, by the way.

I have been through the Java site, but I really want some hands-on advice, rather than what is theoretically possible.

TIA
 
Hi Tia

I haven't used it personally, but I found this to be a great read on JOGL, the Java API for OpenGL:

JOGL

Hope it gets you started!
 
Hands-on advice ?
If you say this project will not be open source, then I guess that means you want to sell it, which means it needs to be a fantastic product.

If you are not sure of what technology you want to write it in, are you sure you will be able to succeed ?

I generally find that if you are about to embark on any project, it is completely necessary to understand the technology you will be using fully.

--------------------------------------------------
Free Database Connection Pooling Software
 
Curious project, I've never heard about a graphic tool in Java. Indeed it will be cross-platform, but I have some doubts about performance.

I think you'll need to find a native and fast implementation for graphic libraries, something like SWT.

Btw, I imagine you already know Java 2d libraries.

Cheers,

Dian
 
Thanks DaWickedRebel and Diancecht for your replies. I've looked at JOGL and SWT and in theory they would do the trick, but I might be pushing them too hard with what I want to do. I'm really looking for comments from people who've either attempted this before or something like it who can say "yes, it'll be fine for performance and compatibility" or "hell no, don't go there, it's a nightmare". :)

Sedj, I've been coding professionally for over 20 years, most recently in C++. Before I dive in to another language I want to know that I'm not going to be wasting my time. If Java can't handle what I want to do, I'll just code natively on all three formats, but I'd rather not waste that time if I don't have to. Your patronising post is really not helpful.
 
Is there any mileage in writing the thing once in Java, and then getting hold of 3rd party Java-to-native compilers for each target platform to improve performance? You'd obviously have to source those compilers; I'm not sure how easily obtainable they are.

Tim
 
Tim, that's an interesting thought, but I would imagine it would be a bug-testing nightmare, as you would be beholden to the compilers to get it right. I would prefer to trust the Java VM on each machine only.

If I was only writing for a single machine, I would consider it (but only if I didn't know C++ :) ).
 
Yes, I think that's probably a wise attitude.

What if you were to write your own native drawing-routine 'engine' (on each platform), and then implement the user-interface control over that using Java JNI? You'd still have to write for each platform, but at least some of your app would be platform independent, saving you some work at least.

Tim
 
Just some thoughts.

A quick googleing on Java 2D Animation shows that this won't we the first attempt, there are examples, tutorials and demos, so maybe you can use them to test performance.

It's true that an interpreted language will always be slower that a compiled one, but taking performance as an objective, this can be reduced by increasing the code complexity.

In the other hand, I don't think that a native implementation needs threes different codes, the reusability can be reallu high.

Maybe a mixed solution could do the trick. Something like mixing SWT (that has a graphical native implementation transparent to Java) and JNI that lets you make native calls to platform specific libraries.

Cheers,

Dian
 
DoobieSister :

Apologies, I didn't mean to be patronising ... you just tend to get a lot of idiotic newbie posts here sometimes - the kind that programme Java for 6 months, and then reckon they can write a world beater programme without really knowing what they are doing.

Anyway, I'm sorry if I caused you offense.

For my two cents on the issue then, I have found that Java really does run out of steam when doing graphics and graphics related stuff (like image manipulation). We recently pulled a project from being written in Java that was doing graphics device stuff and image operations because it was just two slow and couldn't handle load very well. We rewrote it in C.

Considering that you know C/C++, and that all Java really does is wrap native calls via JNI when doing graphics stuff, I would just code it in C, and compile natively, using as much ANSI as you can !

Cheers

--------------------------------------------------
Free Database Connection Pooling Software
 
Thanks for the thoughts - lots to think about.

Sedj, no problems, I understand the "idiotic newbie" comment, I see that all the time. And I know that I am being deliberately "efficient" (or is that just lazy?) by not learning everything I can about Java before making the decision about which way to program my application. But as I'm sure you know, you can get a long way down a road before finding out it's the wrong road, and I've learnt that it's better to just ask directions from someone who's been there before embarking. :)

So no hard feelings!

Your two cents are precisely what I was looking for - what was the main cause of "steam loss"? Size of images? Or just slow calculations? I am used to working with low-res proxies for real-time operations, and then rendering a high-quality image while the user makes a cup of tea. Any comments?
 
I mean by "running out of steam" two things ... one, it was just not quick enough, and two, the more you hammered it, the slower it went. Memory usuage was a nightmare aswell, as was CPU usuage.

To give you an idea of what we were doing, we wrote an imaging server. This would recieve requests for images (maps usually). The server would need to in effect "paste" or mosaic a few source images together, then cut out the desired part. Optionally, graphics and text were drawn over the map.

We used the JAI API to do the mosaic and cropping operations, and then Graphics2D to do the graphics stuff.
Image size was generally 500 to 2000 pixels, and from 30k to 300k in file size.

It just was not quick enough. When I rewrote it in C (having to learn C as I went, lol), it was between 10 and 20 times quicker than the Java version. We used the GD library to do all the mosaic and crop operations, aswell as for the graphics work.

Using Java, an image would take 1 to 2 seconds to create. Now, they are between 100 and 300 milliseconds.

I'm sure its just because there is so much native interface (JNI basically) between the Java APIs and the graphics devices - it just destroys the turn around time.


--------------------------------------------------
Free Database Connection Pooling Software
 
Some good comments on this post! Here is a little more info. Java 2D graphics now supports OpenGL and - it is fast. The not as good news is its picky about which OpenGL cards and OSs - (see: There is no doubt that OO languages like Java and C++ are going to cost time at initialization compared to C. If you are witing "shorts" this can be an issue.
If you do decide to try Java, check out they are developing an enhanced Java 2D library which includes scenegraph suport, a MVC framework and some basic animation objects.
Good Luck!
 
Great comments there, thanks! I'll check out the links.

Hmmm, the best place to look for fast graphics is normally games - a quick google brings up lots of mobile phone Java games, but it's hard to find dedicated Java desktop games. Is that because there's not many, or it's too tricky to write them fast, or I'm just looking in the wrong place?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top