Java 3D for fast 2D painting?

Hi,

We are writing a music notation program, which uses of course only 2d images (drawn as quads with textures, because it’s much faster than Java 2D). At the moment our library is JOGL, and it works great.
Now we have a little problem with some Vista systems which don’t have OpenGL video drivers up to now. So we thought about adding a Direct3D output.

I noticed that Java 3D supports both OpenGL and DIrect3D, so that’s great. I can write on a higher abstract level and Java 3D does the low level job for me.

My question: Is Java 3D ok for our purpose? I mean, isn’t it too high level? Before we rendered thousands of symbols very quickly with some OpenGL, now it seems that I hav to create a Java object for each symbol? That is quite a lot of overhead. Or should I use the pure immediate mode, which is - hopefully - much faster?

Thanks :slight_smile:

Andi

Have you tried Java2D and its various pipelines? There’s a an OpenGL pipeline that uses immediate mode OpenGL (which I’ve heard is is as fast as JOGL in immediate mode) as well as a software mode pipeline, as well as the D3D pipeline, though this D3D pipeline is quite hopeless at the moment, though it will be as good as the OGL one (very fast) when they release Java 7 (or maybe in the Consumer JRE update which will be an update to Java 6!!).

While I’ve never programmed in Java3D I’ve found that it (and LWJGL and JOGL) often don’t work for whatever reason.

If I was you I would use Java2D’s OGL piepline (VM argument ‘-Dsun.java2d.opengl=True’) and if there are driver troubles then use the software pipeline (-Dsun.java2d.noddraw=true).

Best wishes,
Keith

We need the high speed and tested Java 2D on many machines, it is much too slow on older ones. Maybe it works on today’s computers, but we want to support some older (lets say, from 2000 on or so) machines too, and our tests showed, that it is too slow.
Even when Java 2D internally uses OpenGL or Direct3D, we believe that it is not as fast as our own implementation, because we know where certain things can be optimized while Java 2D has to “guess”, and we need the full control (e.g. the “hope” that Java 2D will manage the textures in the right way is not enough for us).

Java 3D: I can only say that the examples work fantastic (e.g. the HelloUniverse runs at 3000 FPS with Direct3D and with 1000 FPS with OpenGL - who said that Java 3D with Direct3D is slow? :wink: ).

I just wondered if Java 3D is a too big overhead for our purposes, and if there is a project like JOGL but for Direct3D?
If not, we will use Java 3D and try to avoid all unnecessary overhead.

Is the immediate mode the right way for this? Are there any good tutorials which show how to get best performance out of Java 3D (if necessary, by ignoring all its features like the scene graph?). Thanks!

If Java2D is fast enough for gaming I’m sure it’s fast enough for notation; it sounds like you are doing something wrong. And though DirectX is supported in Vista, it is not supported outside Microsoft platforms such as Mac, or Linux. And don’t conform to Microsoft’s OS bashing, it’s just plain unfair on everyone else :’(

And you are aware that there is no such thing as 1000FPS, let alone 3000FPS; your monitor has a maximum refresh rate which is usually around 70-80FPS. That figure is no depiction on the performance of either library, and experienced graphics coders often find little (if any difference). When you begin to render full scenes you will most likely find OpenGL outperforming DirectX as Sun appear to have put more effort into it - which is no surprise as DirectX conflicts with their “cross platform” concept.

But nonetheless your implementation seems a little faulted, are you using the appropriate double buffering routines, and accessing the graphics properly … i.e.

         // initializing
        int offset = 0;
        int buffer[] = new int [width*height];
        int scansize = width;
        MemoryImageSource _source =new MemoryImageSource(width ,height,_buffer,offset,scansize );
        _source.setAnimated(true);
        _source.setFullBufferUpdates(true);
        Image _imageBuffer= Toolkit.getDefaultToolkit().createImage(_source);
        // setting pixels
        _buffer[x+y*width] = colour;

        // updating
        _source.newPixels();                      // will copy _buffer to _imageBuffer 

Buffered images are slow; in fact I was able to draw (shaded) perspective correct texture mapped polygons in software far quicker than I could copy the data to a BufferedImage. And the methods making use of the raster sometimes do not work as the format being used might be byte instead of int.

Thanks for the reply, but, sorry, I have never seen a good game written in Java 2D. Do you know one, that proves your statement?

Perhaps it’s all possible in Java 2D… I am not somebody who wants to spend nights over optimizing pieces of code, I am a programmer that want to develop a music notation software (music notation is the main topic, not optimizing some output engine).

The reason why I think about Java 3D is the following train of thoughts:

  • OpenGL works great (JOGL would be the solution!), the method works, it allows even 3D effects later (not possible with Java 2D)
  • But: Vista (arrgh! I hate it, but many people have it, so I can not ignore it) does not support OpenGL from the beginning, so there must be OpenGL drivers from the video card manufactures. There are still machines without OpenGL support (example: a notebook from Dell with Intel GMA 945, which is quite common)
  • Idea: Vista certainly supports DirectX.
  • Idea: Use OpenGL when possible (all OSs but Microsoft’s…), and DirectX otherwise.
  • Try to find a library for DirectX -> not found.
  • Try to find a library for OpenGL and DirectX -> found: Java 3D.

If there is the possibility to do the same things with Java 2D, I will try it immediately (really, I’d like to avoid that enourmous Java 3D overhead). But I have seen no demo that shows the great speed of Java 2D yet…

[quote=“keldon85,post:4,topic:30122”]
I never said that DirectX will be the only output engine… DirectX is an addition for Windows/Vista machines with no or bad OpenGL support. In fact I don’t like DirectX, but I can’t tell my users that they must buy a new Linux computer…

I just noticed a problem: The immediate mode seems not to be implemented for DirectX at the moment :frowning: Is it planned for the future?

I’ll have to try the retained mode, lots of overhead…

Runescape runs entirely in Java2D (or did last year); in fact here are a few others:

Or for a more complete list:

Wow, this one is indeed astonishing. I’ll have a further look on it. Thanks for the links!

That’s exactly what I thought. I was thinking for ages that Runescape ran Java3D through 1.1, but Java3D wasn’t bundled with the old Java runtime environments. Then I realized that my code spent more time copying to buffered images than it did creating them.

But it could be your painting scheme or some really obscure speed issue with an API call that shouldn’t really take any time that is making Java2D seem slower than it should be.

But do keep us all posted, I would like to see how the notation software turns out, especially being a musician and all.

The only reason that OpenGL is not working on Vista is because the card manufactureres haven’t caught up yet. Woogley had the same issue, but he fixed it. Check out this for a possible answer http://slick.javaunlimited.net/viewtopic.php?t=429.

If you want a little easier time using OpenGL, you can look at Slick. I is a 2D library to make it easier to do 2D in OpenGL.

http://slick.cokeandcode.com/

Also, there is PowerTab http://www.power-tab.net/ although it is geared specifically for guitars.