Paint into an image in nifty, updated image does not change[solved]

Hi,
I’m wondering how I get a own drawn image, or an edited image into nifty on-the fly changed outside simpleInitApp().

My problem is, that this works only in simpleInitApp() (imageMap is my edited image):

    NiftyImage nimg = new NiftyImage(nifty.getRenderEngine(), new RenderImageJme(new Texture2D(imageMap)));
    Element niftyElement = nifty.getCurrentScreen().findElementByName("monmapimage");
    // swap old with new image
    niftyElement.getRenderer(ImageRenderer.class).setImage(nimg);

This changes the image in nifty, but only with loaded images:

    NiftyImage nimg= nifty.getRenderEngine().createImage(nifty.getCurrentScreen(),mapFile, false);
    Element niftyElement = nifty.getCurrentScreen().findElementByName("monmapimage");
    // swap old with new image
    niftyElement.getRenderer(ImageRenderer.class).setImage(nimg);

so how to change edited images in nifty outside simpleInitApp()?

Change the data in there… the image should update.

Edit: or maybe nifty is batching it somehow now? Sorry… I don’t use nifty I was just guessing.

Yup, it seems that some caching is going (or maybe nifty simply don’t notices the updates in my Texture2D ‘imageMap’).
Cause my code works as long as I call my method inside simpleInitApp().
If I call the first code example from somewhere (for example from a buttonclick in game), then only the old image is shown, not my changed image.

Maybe I need to put my update somehow in simpleUpdate()? Or is there something like niftyElement.invalidate(), to let nifty know I changed the image?

Anyway what GUIs do you use? I often find nifty a bit clumbsy, so maybe other GUIs are worth to test (toneGui?, HeroDex GUI?)?

If nifty is configured to use batching (I d’ont remember how you do this, but you probably know it if you do it), it generates a texture atlas with all your images.
So it’s not really using your image afterward so if it changes, Nifty doesn’t know it.
Without batching though, it should work.

the different alternatives are
Nifty
Lemur
TonegodGUI
Javafx embed in JME3
Search on the forum you should find

I call the method now from simpleUpdate(float tpf), same problem.

could it be the problem that I use an loaded image and then draw on it?
When I call my method from simpleInitApp(), all works like expected.
No I have not enabled a special caching, it’s plain nifty.

    Texture texRad, monMap;
    Image imageMap;
    ...

    texRad = assetManager.loadTexture(radarFile);
    imageMap = texRad.getImage();
    ...

                            manipulatePixel(imageMap, x, y, color, true);   //set border in owner color
    ...

   NiftyImage nimg = new NiftyImage(nifty.getRenderEngine(), new RenderImageJme(new Texture2D(imageMap)));
   Element niftyElement = nifty.getCurrentScreen().findElementByName("monmapimage");
   // swap old with new image
    niftyElement.getRenderer(ImageRenderer.class).setImage(nimg);

In theory, i fit’s a batching issue, then it works only from simpleInit because nothing has been drawn yet. Once something is drawn then it’s batched and somehow that has to be retriggered.

I know almost nothing about nifty so I’m just guessing. For example, I don’t know why resetting the image wouldn’t cause a rebatch.

After days of searching I found finally this:

This also works on my Nifty-image.

Well it was really frustrating, all that no longer working jmonkey-posts, the non-existing or bad nifty examples and all.

However hope others can save this frustation now and I’m happy that I dont have to dump nifty, which would cause a lot of work.

Theres a whole manual for nifty linked in the wiki…

Is there a WORKING manual again now?
The half of the ‘nifty-manuals’-links here in forum lead to dead/outdated ends.

And by the way, if ‘RTFM’ would really help on that question, I would not have asked here in forum (and others not too), normen.

Heres the wiki page with the link to the manual which works just fine: http://wiki.jmonkeyengine.org/doku.php/jme3:advanced:nifty_gui

Your general assessment regarding “if its in the manual there would no forum post about it” is dead wrong.

…there is no such setUpdateNeeded() in your link and none in the ‘nifty-gui-the-manual-1.3.2.pdf’ I downloaded some time ago, nor did I found that topic there (Besides it’s easier when one already knows the answer, makes lots easier what to search for).

I’m not sure if it’s ‘dead’ wrong. I guess the most people here in forum search first, before asking, so did I.

So where did you see a link in your post that would be the answer on this threads-topic?

Besides knowing the anwer but writing only ‘RTFM’-posts wastes both, the readers and the posters time.

You complained about the situation of nifty documentation in general, I said theres a full manual. Now you accuse me of “writing RTFM posts”.

Hi, if you are having problems with the nifty GUI manual and wiki, I recommend downloading the source release from https://github.com/void256/nifty-gui/releases .
Nifty 1.3.2 is bundled with jMonkey.

Many people hate nifty, but after seeing many UI frameworks, I actually like it. A lot.
Despite the problematic documentation, it’s either NiftyGUI or self-written UI.

Note: anyone contemplating that route should at least start with Lemur. It’s made to be modular and parts of it can be reused directly (mouse handling, input management, etc.) without starting from scratch. Also, it’s implementation is very lightweight and JME-friendly and designed for easy composition/extension.

1 Like

It’s very nice, what pspeed did with Lemur. https://www.youtube.com/watch?v=LhLWZW-ZeZw

Ok, then sorry normen and thank you for your help.