Java3D - On Screen Text - HUD - Simple 2D Text?

Hi all,
I’m new to java 3d, and am wondering how I go about putting some simple text on screen…I’ve been reading around and have tried Text3D and Text2D, but they seem to be releative to the 3d world…and my camera is moving around so the text isn’t really 2d on screen text.

My simple 3d class extends the JFrame, and wanted to know if there was any examples of using java3d and putting some 2d text on screen…like a counter or something.

Thanks,

Ben

I have been trying to figure this same thing out for about a day now. And after realizing that javax.media.j3d.Canvas3D extends java.awt.Canvas and java.awt.Canvas exends java.awt.Component, you can simply call the getGraphics() method, like this:

[quote]Canvas3D canvas = new Canvas3D(config);
Graphics g = canvas.getGraphics();
[/quote]
Then use the traditional drawing methods of java.awt.Graphics to draw directly to the Canvas3D.

Hi Jamison,
well thanks for your idea…I tried this:


Graphics g = canvas.getGraphics();
g.setFont(new Font("TimesRoman", Font.ITALIC, 28));
g.drawString("abcdefeghijklmonopdkdkdkd",80, 80);

But what I find is, no matter how I do it, I always seem to get a flicker…never seems like a smooth on screen text…its like every few frames it flickers or something…any ideas on how to fix this?

Thanks,

Ben

I don’t have any problems. Perhaps your doing something wrong? Here’s some sample code:

[quote]import java.awt.;
import javax.swing.
;
import javax.media.j3d.;
import com.sun.j3d.utils.universe.
;

public class Test extends JFrame implements Runnable {
int fps = 30;
Graphics screen;

public Test() {
	setSize(400, 300);
	setResizable(false);
	setDefaultCloseOperation(EXIT_ON_CLOSE);

	GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
	Canvas3D canvas = new Canvas3D(gc);
	getContentPane().add(canvas);

	BranchGroup scene = new BranchGroup();
	scene.compile();

	SimpleUniverse su = new SimpleUniverse(canvas);
	su.addBranchGraph(scene);

	setVisible(true);

	screen = canvas.getGraphics();

	new Thread(this).start();
}

public void run() {
	while(true) {
		try {
			screen.setColor(Color.white);
			screen.setFont(new Font("TimesRoman", Font.ITALIC, 28));
			screen.drawString("abcdefeghijklmonopdkdkdkd",80, 80);

			Thread.currentThread().sleep(1000/fps);
		} catch(InterruptedException e){}
	}
}

public static void main(String args[]) {
	new Test();
}

}
[/quote]

I’m sorry, but that source doesn’t look like a particularly good solution.

The 2D rendering is not synchronized with the 3D rendering at all.

You know what? I’m a beginner to J3D too. I was only giving him source code that worked for me from what I found myself by looking through the documentation.

Here are a couple of relevant threads:
Dynamic Textures for UI followed by Best Approach to UI Panes also HUD on top of Canvas3D.

Something like this. You have to override Canvas3D.postRender() to make sure the HUD is drawn everytime a frame is rendered. This is supposed to be quite slow, but since drawAndFlushImage was introduced it works good enough.

Been a while since I worked with Java 3D, but using postRender() used to have an awful performance impact - anyone know if this is still the case.

We used to end up aligning quads with the screen and using dynamic textures for optimum performance.

Kev

Hi

It’s probably suffered a bit of bit rot by now, but there is a HUD system for Java 3D and a demo application on the newdawn software site here.

HTH

Endolf

Well as of J3D1.4.0_01 the performance is still bad (I am going through the pains of having to convert over to a new hud b/c of it). By using JProfiler I discovered that postRender was taking up 68% of all computation time. Thats horrible for just displaying hud stuff.

Well, I think I’m gonna try and use the HUD stuff from j3d.org.

Hey.
So I am trying to use the j3d overlay package and I can’t seem to get it to work.
This is what I am doing:

  • Extended Canvas3D (I was previously using drawAndFlushImage but commented out that code)
  • Added ImageOverlay with a BufferedImage.
  • Getting Graphics2D from image and drawing to it the HUD Components

So here is what I do when creating Image Overlay in the constructor of Canvas3D


BufferedImage imageBuffer = OverlayUtilities.createBufferedImage(dimension,true);
Graphics2D g2d = imageBuffer.createGraphics();

ImageOverlay imageOverlay = new ImageOverlay(this,dimension,true,true,imageBuffer);
imageOverlay.initialize();
imageOverlay.setVisible(true);

Then in the postRender function


// do update HUD graphics with g2g
updateHUDGraphics(g2g);
imageOverlay.repaint()

Am I doing something wrong?

Well, I’ve asked the question over at the java.net forums about methods for rendering HUDS.

A poster replied and mentioned that performance is affected by the size of the image that you call drawAndImageFlush on.

Check it out here

http://forums.java.net/jive/thread.jspa?threadID=18922

ok, I’ve just converted over to drawing to seperate images (panes) like described in the above post and I’m getting worse performance.
I’m down to 15FPS instead of 30FPS with the all in one image.

Any suggsetions?

How about using the PlatformGeometry class to do all 2d drawing. Is there anything to be aware of when using PlatformGeometry?