Render the Nifty GUI on a 3D object

Hi,



is it possible to render Nifty on a quad or a box as a texture ?

Yeah, you just need to create a new viewport, assign it the NiftyGuiProcessor, then make it render into a FrameBuffer. You can get the texture from the framebuffer object and put it on a box or 3D object.

Hi!



My problem is, that i'm very new with the jm3 code … Seems to be complete different to jm2 … When you say "just need to create a new viewport, assign it the NiftyGuiProcessor…" then I have no plan how to realize it…



I think JM3 is a great project and i really want to learn how to use it. Could you give one more hint please ?  :wink:



Greetings,

Chris

I see. Well if you combine what you learn from TestNiftyGui and TestRenderToTexture you can take both of those concepts and combine them together to get the desired result. Instead of creating nifty for the gui viewport, you create it for another one, then assign a framebuffer to it like in the TestRenderToTexture.

Here's a some code that does the job:

ViewPort niftyView = renderManager.createPreView("NiftyView", new Camera(1024, 768));
        NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager,
                                                          inputManager,
                                                          audioRenderer,
                                                          niftyView);
        nifty = niftyDisplay.getNifty();
        nifty.fromXml("all/intro.xml", "start");   
        niftyView.addProcessor(niftyDisplay);

        FrameBuffer fb = new FrameBuffer(1024, 768, 0);
        fb.setDepthBuffer(Format.Depth);
        Texture2D tex = new Texture2D(1024, 768, Format.RGB8);
        fb.setColorTexture(tex);
        niftyView.setClearEnabled(true);
        niftyView.setOutputFrameBuffer(fb);

        Box b = new Box(Vector3f.ZERO, 1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
        mat.setTexture("m_ColorMap", tex);
        geom.setMaterial(mat);
        rootNode.attachChild(geom);



Result

Very nice! Thanks a lot!