Nifty GUI rendered behind the scene!

Hi,



I’m currently experimenting with JME3 and Nifty GUI and everything seems to be working perfectly so far

  • except the fact that my Nifty GUI is rendered behind all the objects I pu into the scenegraph and I’d like it to be rendered in front of it.



    Here’s some example code:



    Main class, just a SimpleApplication

    [java]package mygame;



    import com.jme3.app.SimpleApplication;

    import com.jme3.material.Material;

    import com.jme3.math.ColorRGBA;

    import com.jme3.math.Vector3f;

    import com.jme3.niftygui.NiftyJmeDisplay;

    import com.jme3.scene.Geometry;

    import com.jme3.scene.shape.Box;

    import de.lessvoid.nifty.Nifty;

    import java.util.logging.Level;

    import java.util.logging.Logger;



    /**
  • test
  • @author normenhansen

    */

    public class Main extends SimpleApplication {



    public static void main(String[] args){

    Main app = new Main();

    app.start(); // start the game





    }

    private Nifty nifty;



    @Override

    public void simpleInitApp() {

    Logger.getLogger("").setLevel(Level.WARNING);



    //Create a box as a scene representation - it will be rendered in front of my GUI :frowning:

    Box b = new Box(new Vector3f(0,0,0), 1, 1, 1); // create cube shape at the origin

    Geometry geom = new Geometry(“Box”, b); // create cube geometry from the shape

    Material mat = new Material(assetManager,

    “Common/MatDefs/Misc/Unshaded.j3md”); // create a simple material

    mat.setColor(“Color”, ColorRGBA.Blue); // set color of material to blue

    geom.setMaterial(mat); // set the cube’s material

    rootNode.attachChild(geom); // make the cube appear in the scene

    flyCam.setEnabled(false);



    NiftyControlState ncs = new NiftyControlState();





    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(

    getAssetManager(), getInputManager(), getAudioRenderer(), getViewPort());

    nifty = niftyDisplay.getNifty ();





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

    // nifty.setDebugOptionPanelColors(true);

    getViewPort().addProcessor(niftyDisplay);







    stateManager.attach(ncs);

    }

    }

    [/java]



    And this is the AppState I use for managing the GUI:





    [java]

    import com.jme3.app.Application;

    import com.jme3.app.SimpleApplication;

    import com.jme3.app.state.AbstractAppState;

    import com.jme3.app.state.AppStateManager;

    import com.jme3.asset.AssetManager;

    import com.jme3.math.ColorRGBA;

    import com.jme3.niftygui.NiftyJmeDisplay;

    import com.jme3.renderer.ViewPort;

    import com.jme3.scene.Node;

    import de.lessvoid.nifty.Nifty;

    import de.lessvoid.nifty.screen.Screen;

    import de.lessvoid.nifty.screen.ScreenController;



    /**

    *
  • @author Max

    /

    public class NiftyControlState extends AbstractAppState implements ScreenController {

    private Screen screen;

    private NiftyJmeDisplay niftyDisplay;

    private Nifty nifty;

    private Application app;



    /
    * custom methods /

    public NiftyControlState() {



    // flyCam.setDragToRotate(true); // you need the mouse for clicking now

    }



    public void displayScreen(String nextScreen) {

    nifty.gotoScreen(nextScreen); // switch to another screen

    }



    /
    * Nifty GUI ScreenControl methods /

    public void bind(Nifty nifty, Screen screen) {

    nifty.registerScreenController(this);

    this.nifty = nifty;

    this.screen = screen;

    }



    public void onStartScreen() {

    }



    public void onEndScreen() {

    }



    /
    * jME3 AppState methods */

    @Override

    public void initialize(AppStateManager stateManager, Application app) {

    this.app = app;

    }



    public void sayHello(){

    System.out.println("HELLO");

    }

    }

    [/java]

    I already found a solution which is applicable to JME2, but as ViewPort#setClearEnabled() is not available in JME3, I need a different solution…



    Any ideas?


  • KM

This

[java]

getViewPort().addProcessor(niftyDisplay);

[/java]

adds the nifty gui to the main viewport.



you have to add it to the guiViewport instead

[java]

guiViewport.addProcessor(niftyDisplay);

[/java]

Yes, it works - thanks!

Just wanna know if the nifty gui components are rendered or not if they are out of fov (like in jME). Because I’m doing it myself !?