Nifty does not properly display GUI after app.restart() when gamma correction is enabled

Hello community,

I discovered a problem with Nifty; I created a settings screen where you can set graphics settings such as resolution, full screen etc. When you click on the apply-button the changes are appliedand the app restarts. I am calling app.restart(); here.

However, the thing is that when I have gamma correction enabled, after the restart the screen looks much darker than before. When I do not have gamma correction enabled it works properly. But I need gamma coorection for my game, otherwise the world will look way too dark!

Does anyone know where this behavior comes from and how to fix it?

Here a screen from the CORRECT looking gui:

and here the gui after the restart (with gamma correction):

Many thanks in advance!

Best regards


Nifty’s UI colors are embedded in many places in the style JAR (nifty-style-black-1.4.2.jar), both in XML resources and in PNGs.

A straightforward solution to this issue would be to create an alternate version of nifty-style-black for use with gamma correction. A more general solution would be to modify the code in com.jme3.niftygui to render UI elements appropriately when gamma correction is enabled.

I think this issue is worth filing at GitHub:
Issues · jMonkeyEngine/jmonkeyengine · GitHub

Hey @sgold thanks for your reply! The thing is that this only happens after the app has been restarted. When I enable gamma correction in the JME Settings Screen right at the beginning everything is also shown fine but as soon as the app is restarted the gui is “broken”.

I really don’t think this is a Nifty issue but more a jME one since Nifty apparently can show GUIs with gamma correction enabled. Only when restarting Things get messed up.

Thanks for the clarification. Still worth opening an issue, I think.

Looks like an issue in the setting when restarting… Is gamma correction enabled in the settings on restart?
(Like output to the console the value of setting.get(‘GammaCorrection’))

Alright, I created an issue about this:

Yes, gamma correction is enabled after the restart, at least according to the app settings.

Here is the Code where I call restart:

public void applyToAppSettings() {
    appSettings.setResolution(getWidth(), getHeight());
    appSettings.setGammaCorrection(true); // force gamma correction

    System.out.println("Gamma Correction = " +appSettings.isGammaCorrection()); // true
1 Like

Alright, I found out what is causing this issue (in my case):

Here is the code again (fixed one line):

public void applyToAppSettings() {
    appSettings.setResolution(getWidth(), getHeight());
    appSettings.setGammaCorrection(true); // force gamma correction

The line of code “causing” this problem is the following:


I found out that when the number of samples has changed to another value than before the gui will look too dark. But if the value does not change everything works fine! Unfortunately, I don’t know how to fix that since this goes deeply into the core of JME probably.

I am (for now) just removing this setting from the settings screen. Sad acutally.

1 Like

Is the whole screen getting dark or just nifty GUI?

Maybe it’s something in Nifty that needs to know the AA setting has changed.

Sorry, I forgot to mention. The whole screen gets darker, so in-game as well.

1 Like

I dug a bit and clearly gamma correction setting is not reapplied. Not sure it can be reapplied with a simple restart.
I’ll continue digging


Thanks for your time, @nehon! :slight_smile:

1 Like

OK, yeah I forgot, but when you switch to gamma correction all textures needs to be reloaded to work properly, because they use a special format.
IMO this is this kind of option where you should ask the user to restart the app so it takes effect.
Also… I’m even not sure you should expose this setting to the user… If you calibrated your lighting with gamma correction on it’s gonna look very dark (as in your shot) if you disable it.

It seems like he wasn’t changing gamma, though.

Also, I wonder if we can throw an exception if the user tries to restart the app with different gamma settings… since it’s not supported.

I guess we could


I was not changing gamma correction. In the settings screen from JME you can check that GammaCorrection Checkbox, right? So, when this is one is checked and I try to restart things get messd up. If it is not checked things work fine. Note: Imagine that the setGammaCorrection(true) line in my method does not exist (I added it later).

But as described above everything seems fine if the samples are not changed, that’s why they are locked now to a fix value. Maybe samples and gamma are kind of interfering with each other?

mhh ok…
A testCase replicating the exact issue would help at this point.

Maybe I can do this later. Currently I am busy finishing the last pieces of my game, sorry…

I have the very same issue, more over the Lemur based screen is blurred with gamma correction on, if I sett gamma correction off it is crystal clear. The blur filter looks better with gamma correction but the whole scene is brutal dark, so that I basically can only feel the shape not really see it if I have already a slightly dark scene.

Set the light brighter helps a bit. And I also use that startup JME pop up to enable/disable gamma correct.

At this point I rather have to statically turn gamma correction off so you are able to see something :wink:

EDIT: I could correct nearly all issues with this two lines


except that the Lemur UI part looks still slightly blurry, it doesn’t look bad to be honest, maybe this is a feature not an issue ;). What I still not get is the batch size, I have many lights (every rocket I fire has a light, as it makes it look more juicy), but I see no difference if I set batch size to forexample 30. Ok this is something different and I didn’t want to hijack the thread.

EDIT2: I guess I do add the blur filter too early so it affects the UI as well, I guess that is a solvable problem :slight_smile:

@nehon Here is a test-case:

package de.gamedevbaden.crucified.tests;

import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Spatial;
import com.jme3.system.AppSettings;

public class SettingsTest extends SimpleApplication {

    public static void main(String[] args) {
        SettingsTest test = new SettingsTest();
        AppSettings settings = new AppSettings(true);

    public void simpleInitApp() {

        // setup test scene
        Spatial testModel = assetManager.loadModel("Models/Jaime/Jaime.j3o");

        AmbientLight light = new AmbientLight(ColorRGBA.White);

        // add input for restart action
        inputManager.addMapping("RESTART", new KeyTrigger(KeyInput.KEY_T));
        inputManager.addListener(new ActionListener() {
            public void onAction(String name, boolean isPressed, float tpf) {
                if (!isPressed) return;
                AppSettings settings = getContext().getSettings();

                // when we change the samples to another value than the value in the beginnen
                // the scene becomes dark and also the stats box is not
                // visible any longer in the bottom left corner
                settings.setSamples(2); // if it is set to "1" restart does work fine
        }, "RESTART");


Everything gets messed up when the samples value has changed! So this is not a Nifty GUI issue here but a jME one.

Please tell me if I can help somehow!

Best regards