Nifty GUI HUD rendering behind 3D objects

I am trying to add a HUD with nifty gui. I’ve followed the examples but still have the problem where the HUD elements are being rendered behind 3D objects in the scene. Anyone know what i might be doing incorrectly?



Here is the code for adding Nifty GUI

[java]NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,

inputManager,

audioRenderer,

guiViewPort);

nifty = niftyDisplay.getNifty();

nifty.fromXml(“Interface/NiftyHUD.xml”, “start”, this);

// attach the nifty display to the gui view port as a processor

guiViewPort.addProcessor(niftyDisplay);[/java]



Nifty GUI xml

[xml]<nifty>

<screen id=“start” controller=“com.monkygames.st.gui.NiftyHUD”>

<layer id=“layer” backgroundColor="#0000" childLayout=“center”>

<panel id=“panel” height=“25%” width=“35%” align=“right” valign=“top”

backgroundColor="#f60f" childLayout=“center” visibleToMouse=“true”>

<interact onClick=“quit()”/>

<effect>

<onStartScreen name=“move” mode=“in” direction=“top” length=“300”

startDelay=“0” inherit=“true”/>

<onEndScreen name=“move” mode=“out” direction=“bottom” length=“300”

startDelay=“0” inherit=“true”/>

<onHover name=“pulsate” scaleFactor=“0.008” startColor="#f600"

endColor="#ffff" post=“true”/>

</effect>

<text id=“text” font=“aurulent-sans-16.fnt” color="#000f"

text=“Hello from jME3” align=“center” valign=“center” />

</panel>

</layer>

</screen>

<screen id=“end”>

</screen>

</nifty>[/xml]

Are you putting your 3d objects in the gui bucket by any chance?

Or are your 3D objects in a post viewport or something? Have you done anything strange about your scene setup?

I just had the same problem and was able to solve it:

I wrongly used the viewPort instead of the guiViewPort object, which are two different objects.

using viewPort from app.getViewPort() results in the described problem.
using guiViewPort from app.getGuiViewPort() solves the problem.

1 Like

My personal suggestion is to keep Nifty as far away from your Gui ViewPort as possible. It is very difficult for Nifty to behave badly if you follow this advice :wink:

Kidding (sorta)… glad you got your answer!

Sorry for reviving an old thread but is there a way to put some elements in back but not others?

Don’t answer that, I found the solution.

You can just add two niftyDisplays, and have them lead to the viewPort and guiViewPort at the same time. And then load the xml elements that you want from each.

[java]
niftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, application.getGuiViewPort());
frontNiftyDisplay = new NiftyJmeDisplay(assetManager, inputManager, audioRenderer, application.getViewPort());
nifty = niftyDisplay.getNifty();
frontNifty = frontNiftyDisplay.getNifty();

    nifty.fromXml("Back.xml")
    nifty.fromXml("Front.xml")

     viewPort.addProcessor(niftyDisplay); 
    guiViewPort.addProcessor(frontNiftyDisplay);

[/java]

Although it does return a weird error.