How to immediately render to Nifty component

I am trying to make an item slot that shows item icons. I want to render the item once and use that texture for the Nifty component. So far I’ve got this:
FrameBuffer fb = new FrameBuffer(100, 100, 1);
Texture2D color = new Texture2D(100, 100, Format.RGB8);
Camera cam2 = cam.clone();
cam2.setLocation(new Vector3f(0, -5, 0));
cam2.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
ViewPort vp = new ViewPort(“itemvp”,cam2);
Geometry clone = g.clone();
clone.setLocalTranslation(0, 0, 0);
renderManager.renderViewPort(vp, 0);
NiftyImage img = new NiftyImage(nifty.getRenderEngine(), new RenderImageJme(color));
Element niftyElement = nifty.getScreen(“start”).findElementByName(“foreground”).findElementByName(“bottom”).findElementByName(“right”).findElementByName(“image”);
I wasn’t too sure what I was doing. I’ve went over relevant JME examples. Anyway, I get this (see bottom right corner):

Here, I am supposed to be holding a (crappy) rock, which means it should show a rock icon in the corresponding slot. Obviously, something is not right there. What is the correct way to do this?

I added
vp.setClearFlags(true, true, true);
and now the icon shows a red background, which is good. But I still don’t see the object (rock).

The code looks fine to me.
On the top of my head :
Could you try with RGBA8 instead of RGB8?
Strictly speaking RGB8 does not exists in opengl specs so it might fail on some hardware

to rule out a nifty issue could you try to render a picture in the gui viewport with the texture? (use the Picture class)

@nehon RGBA8 didn’t make a difference. Using a picture didn’t either, so it must be something with the code above. Hmm…

Welp, the problem was mainly caused by different resolutions between the camera and framebuffer. Solved.

1 Like