jMonkeyEngine / jmonkeyengine

A complete 3-D game development suite written in Java.
http://jmonkeyengine.org
BSD 3-Clause "New" or "Revised" License
3.78k stars 1.12k forks source link

changing BitsPerPixel in AppSettings interferes with StatsAppState #801

Closed stephengold closed 4 years ago

stephengold commented 6 years ago

In windowed mode, my attempts to change the display's bits per pixel cause the StatsAppState bitmap text to disappear. But some geometries (such as the blue cube and the darkeners) are unaffected. I see this issue both with JME 3.1 and 3.2 . Interestingly, I don't see it in full-screen mode.

Here is my test app:

package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;

public class Main extends SimpleApplication {

    public static void main(String[] args) {
        AppSettings initialSettings = new AppSettings(true);
        initialSettings.setBitsPerPixel(24);

        Main app = new Main();
        app.setSettings(initialSettings);
        app.start();
    }

    @Override
    public void simpleInitApp() {
        viewPort.setBackgroundColor(new ColorRGBA(0.3f, 0.3f, 0.3f, 1f));

        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);

        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Blue);
        geom.setMaterial(mat);

        rootNode.attachChild(geom);
        inputManager.addMapping("changeBpp", new KeyTrigger(KeyInput.KEY_P));
        ActionListener listener = new ActionListener() {
            @Override
            public void onAction(String name, boolean keyPressed, float tpf) {
                if (name.equals("changeBpp") && keyPressed) {
                    goWindowed();
                }
            }
        };
        inputManager.addListener(listener, "changeBpp");
    }

    void goWindowed() {
        AppSettings newSettings = new AppSettings(false);
        newSettings.copyFrom(settings);
        newSettings.setBitsPerPixel(16);

        setSettings(newSettings);
        restart();
    }
}
stephengold commented 6 years ago

I see a similar issue if I attempt to change the display's MSAA setting using AppSettings.setNumSamples().

Nehon commented 6 years ago

I think this is the same issue as https://github.com/jMonkeyEngine/jmonkeyengine/issues/380

stephengold commented 5 years ago

I wonder if this issue depends on the LWJGL version used.

stephengold commented 5 years ago

Occurs with both v2.9.3 and v3.1.6 of LWJGL.

stephengold commented 5 years ago

A possibly relevant topic at the Forum: https://hub.jmonkeyengine.org/t/problem-with-gui-z-order-after-graphics-restart/40985

Ali-RS commented 1 year ago

I am still able to reproduce this issue in JME 3.6.0-stable with LWJGL 2 on Linux. Running TestIssue801, after pressing the P key on the keyboard it shows a blank window.

A new fix is submitted in #1988

stephengold commented 1 year ago

My tests using TestIssue801 confirm that the issue really is solved this time.