jPCT rendering into JavaFX 2.0

Started by rjm49, March 07, 2012, 03:48:34 PM

Previous topic - Next topic

rjm49

Hi folks/Gruess Gott,

I'm new to jPCT and liking it!  Such compact and no-nonsense toolkits are so rare these days.  I have come from Java3D, which I can only conclude was never designed to actually be used by anyone.

I am trying to integrate jPCT with JavaFX 2.0.  This is because JavaFX's 3D own features cannot be used on my XP netbook (Mobile Intel 945 Express graphics chipset), even with all latest drivers.  A shame, given how common these chipsets are.

So the aim of my project - to get jPCT rendering onto a JavaFX Image, so that it can be viewed (via ImageView) as a panel showing jPCT 3D coolness, in the JavaFX scene.

I have achieved this, but not in a satisfactory/stable way.  Before we go into details of my horrid hacks, I'd be interested to hear if anyone else has had a go at this, and/or whether there is a "standard approach" to such a thing.

In the case of my project, I am trying to simply display the jPCT HelloWorld "spinning cube", in a single ImageView in the JavaFX scene.  So I need to get frames from jPCT and update the Image/ImageView repeatedly to animate it.  Not trying to do event handling or anything at this point.

I am happy to delve into code, I firstly just want to see if anyone else has had a go, or thought about it?

Thanks/Danke!

Russell (rjm49)

EgonOlsen

As far as i know, nobody tried this so far. What is ImageView? It is comparable to java.awt Image or more like a Component?

rjm49

#2
Hi Egon, thanks for the quick response.  Yes, I should clarify:

javafx.scene.image.Image is the approximate equivalent of java.awt.Image;

javafx.scene.image.ImageView is a component (in JavaFX called a Node) for viewing Images;

Image works mainly as a loader class - you can feed a URL or InputStream into it to populate it with image data.  ImageView#setImage() then takes an Image and displays it (you can crop/rotate it etc using ImageView's utility methods).

A point of note however:  javafx.scene.image.Image is not compatible/interchangeable with java.awt.Image!  Indeed there is no official backward-compatibility between Swing/AWT/SWT/Java2D/Java3D and JavaFX 2.0. (Back in JavaFX 1.x they had a special Node that let you show Swing components in JavaFX.  In 2.0 only the other way round is true!)

I have had limited success with two approaches:

A) repeated acquiring (snapping) a java.awt.BufferedImage from jPCT, converting this into a JavaFX Image, and using imageView.setImage(imageFromjPCT) to set the new content.  For this I have to run a thread to do the rendering loop in jPCT, and another thread to do the "snaps".  JavaFX has another thread doing its GUI stuff.

B) I have also tried the "other way round" with the jPCT thread "pushing" images to JavaFX by way of a method call.  Then you don't need a "snapping" thread.  Again, JavaFX has its own thread doing its GUI stuff.

Both approaches tend to hang on the JavaFX side after about a minute, and version (A) has a habit of not initialising properly (thread non-safety I think).  JavaFX does not have a "game loop" model, its threading is implicit, so I cannot just call out for a new jPCT frame every time JavaFX "refreshes".

Having re-read all this, I suspect this is more a JavaFX problem than a jPCT one.  I just wondered whether there was preferred way of extracting BufferedImages from a running jPCT thread in a nice thread-safe manner.

Thanks!

EgonOlsen

Which renderer are you using? Software, hardware or awtgl?

rjm49