Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Best solution to display 2D layer on top of 3D scene  (Read 5816 times)
0 Members and 1 Guest are viewing this topic.
Offline faldo1

Junior Newbie

« Posted 2012-05-09 11:15:12 »


I write a little Java3D program and I need to display a 2D layer on top of my 3D scene with

- dynamic stats (FPF, memory usage, ...)
- dynamic hour (rendered as an analog watch).

I searched on the web and I think I would use a PlatformGeometry

So, I created the following structure

PlatformGeometry => TransformGroup => BranchGroup => Text2D

But I have to create/update the Text2D on every frame.

When I try to do that (add a Text2D as a Child of the BranchGroup), I get an error Group: only a BranchGroup node may be added

I get an equivalent error when I try to remove previous Text2D child from the BranchGroup.

I think I gave the needed capabilities to the BranchGroup.


I also see I can remove the BranchGroup from the TransformGroup without getting any error. But, I don't think it's efficient on every frame to

- remove '2D stats' BranchGroup from '2D stats' TransformGroup
- create new '2D stats' BranchGroup
- create new Text2D and add it as child to '2D stats' BranchGroup
- add new '2D stats' BranchGroup to the '2D stats' TransformGroup.

So, what is the best solution ?

Thanks for all.

Offline ylliac

Junior Newbie

« Reply #1 - Posted 2012-05-09 12:02:36 »


If you just have to update the text of the Text2D, setString() should be enough.

If you have to create another Text2D, the solution I see is :

- Detach the Text2DBranchGroup. This branchgroup should have the capability BranchGroup.ALLOW_DETACH, Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE and the parent node should have the capabilities Group.ALLOW_CHILDREN_EXTEND and Group.ALLOW_CHILDREN_WRITE.
- Remove the Text2D from the Text2DBranchGroup. No exception will be thrown I think because the Text2DBranchGroup is no longer alive.
- Create a new Text2D and add it to the Text2DBranchGroup.
- Attach the Text2DBranchGroup to his last parent.

Offline faldo1

Junior Newbie

« Reply #2 - Posted 2012-05-09 13:06:39 »

Hello Antoine,

I tried what you said and it works. The Text2D is just a little bit blinking but it doesn't matter.

Thanks / merci

But I see a strange effect.

The z offset of my Text2DBranchGroup is -2
In my scene, there is a tree at z = -50

The Text2D in the Text2DBranchGroup is displayed on top of tree trunc, ok, but the tree leafs (transparent texture) are displayed on top Text2D  !

It seems there is a z-buffer bug between 3D scene and PlatformGeometry.

Maybe is it related to my clipping ?


I need these values to display near objects and very far away ones.

Any idea ?

Pages: [1]
  ignore  |  Print  

Riven (208 views)
2019-09-04 15:33:17

hadezbladez (4948 views)
2018-11-16 13:46:03

hadezbladez (1824 views)
2018-11-16 13:41:33

hadezbladez (5225 views)
2018-11-16 13:35:35

hadezbladez (1032 views)
2018-11-16 13:32:03

EgonOlsen (4416 views)
2018-06-10 19:43:48

EgonOlsen (5249 views)
2018-06-10 19:43:44

EgonOlsen (2988 views)
2018-06-10 19:43:20

DesertCoockie (3883 views)
2018-05-13 18:23:11

nelsongames (4314 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!