I want to display a spatial (or the rendering of a spatial/scene) in my HUD interface. I'm really not sure how to go with this. I have search the documentation, but all the queries I search yields no result, and all I could find about images is that one can specify one with the setBackgroundImage method in the builder and setImage from the ImageRenderer class. The latter takes a String or a NiftyImage, but I'm not sure how to create one without loading an image file.

Any help to understand this (if even possible) is appreciated. Thanks!


1 Answer 1


There is but one way I can imagin to get this working.

Creating a new NiftyImage as it is needed to get requires two arguments:

  1. the NiftyRenderEngine you can receive from the current Nifty-GUI instance using the getRenderEngine function
  2. A RenderImage that is part of the SPI.

The key is to implement the RenderImage yourself. To be more precise you have to overload RenderImageJme that is used by the JME-Renderer for Nifty to to define images. This class implements a getTexture() method you can overwrite to send in a alternative texture.

If you render the things you want to display to a texture and return this texture in your own implementation of the RenderImageJme, then you should be able to display what ever you want.

  • \$\begingroup\$ where is that implementation? de.lessvoid.nifty.spi.render.RenderImage is an interface and has only 3 methods : getWidth(), getHeight() and dispose(). Do you mean com.jme3.niftygui.RenderImageJme ? \$\endgroup\$ Apr 4, 2012 at 14:44
  • \$\begingroup\$ Exactly. <code>com.jme3.niftygui.RenderImageJme</code> is the implementation of <code>de.lessvoid.nifty.spi.render.RenderImage</code> that is used by the render display JME uses. So you have to extend <code>RenderImageJme</code> in order to use it with the render device of JME. If you implement <code>RenderImage</code> and not <code>RenderImageJme</code> you wil receive a <code>ClassCastException</code> as the JME render device performs a unchecked cast. \$\endgroup\$
    – Nitram
    Apr 4, 2012 at 14:59
  • \$\begingroup\$ then I suspect the magic happens here (NiftyImage) : this.imageMode = ImageModeFactory.getSharedInstance().createImageMode(null, null); where it returns a JME implementation of ImageMode? \$\endgroup\$ Apr 4, 2012 at 15:06
  • \$\begingroup\$ I should. But as I just saw the RenderImageJme offers a constructor that should do what you want. Using RenderImageJme(Texture2D). You need to get the graphics you want to display into this Texture2D using render-to-texture. The instance if the RenderImageJme can we wrapped into a NiftyImage using new NiftyImage(nifty.getRenderEngine(), newRenderImageJme). That should do the job. \$\endgroup\$
    – Nitram
    Apr 4, 2012 at 15:12
  • \$\begingroup\$ Forgot about this question! But this is what I ended up using and it works great! I made an utility class that received a root node and from which the camera could be controlled, and it allowed making UI views of the same scene from different angles (ex: rear view mirror in a race, bullet-time view on a missile, etc.) or display custom scenes (3D map, model, etc.) seemlessly. Got me good marks on my assignment. \$\endgroup\$ Dec 5, 2012 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .