Offscreen rendering with nifty gui?

Hello together,

I want to implement dynamic screens (MFDs) for a space game like a radar display, status indicator and so on…
Is it possible to perform offscreen rendering to Nifty elements? If yes, how?


Yes, that’s possible.

Basically, you update your elements in code. I would recommend you to read the tutorials about Nifty in the wiki.

Best regards,

One year ago when I used Nifty for the last time there seemed to be only the possibility to generate textures by loading a texture file. Thus the only option I know from is rendering and exporting to a texture file and reopen it by nifty. This is exactly the thing I didn’t want to do.

Is there a possibility to directly retrieve a Texture2D object from a Nifty panel?


Depending on your screens… maybe nifty is overkill for what you want to do?

There are certainly easier ways to pop up some off-screen renders in a HUD.

Yes I know but offscreen rendered panels is not the only purpose. Lets say: I have a Gui defined using switches, buttons and menus and so on… Nifty XML offers a good tool base to efficiently structurize a Gui layout but I wanted to combine the Gui layout with rendered parts (2D or 3D or whatever) like:

  • A configurable radar screen consisting of clickable buttons/menus and a panel containing a 2D grid with all the objects.
  • dynamic shield and hull damage display containing a 3D model of the vessel indicating damaged zones and labels for descriptions. Also a Nifty (or whatever) button to allcoate repair priorities.
  • 3D orbital diagram showing vessel trajectories relative to an celestial body overlaid by labels giving exact numerical information. A button or a Drop Down menu is required to switch through the reference bodies. You can see this in Orbiter space flight simulator:


So our current problem consist of two points:

  • In Lemur the access of Texture2D objects is very simple but we do not know a structured way to efficiently define Gui layouts so we have to code them manually and watch the layout directly within the app by starting and stopping the application.
  • On the other hand Nifty comes with a closed tool chain (XML, Styles and built in editor) but with difficult implementation of dynamic textures (We don’t know the way to retrieve a Texture2D reference).

Regards, Harry

Yeah, but if you think you will expose nitfy’s XML to a user as a “configurable UI” then you are in for lost of fun, I suspect.

Either way, if you are letting end-users configure a UI then you will want to come up with some sort of simplified abstraction.

I’m not sure what this means. Don’t you have to do this with nifty XML also? I mean, the SDK has an editor built in but in my experience that starts to become unworkable pretty quickly… especially if you have off-screen rendered elements or anything that is code-backed or remotely dynamic.

Use a separate Viewport to draw onto a texture. Then apply that texture to a Nifty Image element.

Nifty nifty = your Nifty instance;
Texture2D tex = the offscreen texture;
Element image = screen.findElementById("ElementId");
ImageRenderer renderer = image.getRenderer(ImageRenderer.class);
renderer.setImage( new NiftyImage(nifty.getRenderEngine(), new RenderImageJme(tex)) );

For this to work, you have to disable Nifty’s texture atlas (Batched Nifty Renderer). You do that by using the right constructor of NiftyJmeDisplay.
This one for example:
NiftyJmeDisplay(AssetManager, InputManager, AudioRenderer, ViewPort)

You’ll have to find out yourself if it’s really a good idea to do it this way :wink: I thought it was too much hassle to use Nifty for the HUD so I’m using simple jME elements.

Which is essentially what Lemur is with some nice sugar on top. Just in case you ever need anything fancier than manual raw positioning and/or want clickability, etc…

Thank you very much. You just gave me some new ideas to check out.