jmonkeyengine icon indicating copy to clipboard operation
jmonkeyengine copied to clipboard

2D screen coordinates broken after updating to 3.8.0-stable

Open Ivan1pl opened this issue 8 months ago • 2 comments

When using fullscreen mode, coordinates in 3.8.0 are shifted. These are the settings I am using for the application:

        AppSettings settings = new AppSettings(true);
        settings.setHeight(1080);
        settings.setWidth(1920);
        settings.setFullscreen(true);

I'm adding a blue quad that should be fully outside of the screen:

        Quad rectangleMesh = new Quad(100, 100);
        Spatial geometry = new Geometry("Rectangle", rectangleMesh).move(0, 1080, 0);
        Material material = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
        material.setColor("Color", ColorRGBA.fromRGBA255(0, 64, 128, 128));
        geometry.setMaterial(material);
        getGuiNode().attachChild(geometry);

The first screenshot is from 3.7.0:

Image

The second screenshot is from 3.8.0:

Image

Notice that part of the quad is visible in the top left corner of the screen, and the framerate is cut off at the bottom.

I am using Linux with Wayland as display server protocol.

Everything is fine when using windowed mode. However, I noticed that 3.8.0 uses a custom tile bar. Past experiences tell me that this might be the culprit.

Ivan1pl avatar Jun 01 '25 18:06 Ivan1pl

Thanks for reporting this.

This may require some further investigation, but so far I do see that there were a few minor PRs related to screen resolution in 3.8 from @stephengold. However, I don't think any of his PRs did anything related to the custom title bar you mentioned, so I suspect that your issue is more likely be related to a recent PR from @bob0bob that added support for multiple monitors, it was a fairly large PR so there could have been some changes in that PR inadvertently caused this issue.

yaRnMcDonuts avatar Jun 07 '25 03:06 yaRnMcDonuts

I think I'm a little late.

I am using Linux with Wayland as display server protocol.

After seeing this thread, I started testing and yes, there is indeed a bug with Wayland (I don't know if it is present on x11).

I don't know why, but when the updateSizes() method is called, the resolution returned is different than the one set to full screen. Specifically, the height of the screen increases by 24px, it is strange.

I print the result on the screen, using the following code:

private void updateSizes() {
        ...
        glfwGetWindowSize(window, width, height);
        int windowWidth = width[0] < 1 ? 1 : width[0];
        int windowHeight = (height[0] < 1 ? 1 : height[0]);
       ...
        // Debug the data obtained
        System.out.println(Arrays.toString(width) + "x" + Arrays.toString(height));
        glfwGetFramebufferSize(window, width, height);
        
        // Debug the data obtained
        System.out.println(Arrays.toString(width) + "x" + Arrays.toString(height));
        int framebufferWidth = width[0];
        int framebufferHeight = height[0];
        ...
    }

My screen has a resolution of 1920x1080, however, it generated a resolution of 1920x1104 (which is exactly a 24px difference).

[1920]x[1104]
[1920]x[1104]

If I subtract 24px when glfw creates the window, I get a GL context with my screen resolution without problems

protected void createContext(final AppSettings settings) {
       ...
        final GLFWVidMode videoMode = glfwGetVideoMode(monitor);
        int requestWidth = settings.getWindowWidth();
        int requestHeight = settings.getWindowHeight();
        if (requestWidth <= 0 || requestHeight <= 0) {
            requestWidth = videoMode.width();
            requestHeight = videoMode.height();
        }
        
        // Intrusive adjustment for window height.
        requestHeight -= 24;

        ...
        // Lets use the monitor selected from AppSettings if FullScreen is
        // set.
        if (settings.isFullscreen()) {
            window = glfwCreateWindow(requestWidth, requestHeight, settings.getTitle(), monitor, NULL);
        } else {
            window = glfwCreateWindow(requestWidth, requestHeight, settings.getTitle(), NULL, NULL);
        }
        ...
    }

Or configure the resolution in the application properties (works the same)

    public static void main(String[] args) {
        TestSimpleWater app = new TestSimpleWater();
        AppSettings settings = new AppSettings(true);
        settings.setResolution(1920, 1080 - 24);
        settings.setFullscreen(true);
        
        app.setSettings(settings);
        app.setShowSettings(false);
        app.start();
    }

I noticed that 3.8.0 uses a custom tile bar. Past experiences tell me that this might be the culprit.

I'm not really sure if that affects you, I tried to disabling the bar but it doesn't change anything. I used the following methods when creating the context (window).

1. glfwInitHint(GLFW_WAYLAND_LIBDECOR, GLFW_WAYLAND_DISABLE_LIBDECOR);
2. glfwSetWindowAttrib(window, GLFW_DECORATED, GL_FALSE);


    protected void createContext(final AppSettings settings) {
        glfwSetErrorCallback(
        ...

        glfwDefaultWindowHints();
        glfwInitHint(GLFW_WAYLAND_LIBDECOR, GLFW_WAYLAND_DISABLE_LIBDECOR);

        ...
        if (settings.isFullscreen()) {
            window = glfwCreateWindow(requestWidth, requestHeight, settings.getTitle(), monitor, NULL);
            glfwSetWindowAttrib(window, GLFW_DECORATED, GL_FALSE);
        } else {
            window = glfwCreateWindow(requestWidth, requestHeight, settings.getTitle(), NULL, NULL);
        }
        ...
    }

Since the last update of LWJGL3 (specifically version 3.3.5 changed this, you can see the notes here), Wayland has changed drastically (in the sense of how low level contexts work), currently EGL is the one used for the wayland context (which is the native way), compared to x11 which GLX uses.

~~Avoiding calling the updatesize() method when opting for full screen, avoids warping the resolution context, is strange, so this may be out of scope in jme3...~~

[EDIT]

Turn on the "resizable" option, avoid this error, I'm not quite sure if this is a low level error, this requires something else to determine what is happening...

    public static void main(String[] args) {
        TestSimpleWater app = new TestSimpleWater();
        AppSettings settings = new AppSettings(true);
        settings.setResolution(1920, 1080);
        settings.setFullscreen(true);
        settings.setResizable(true);
        app.setSettings(settings);
        app.setShowSettings(false);
        app.start();
    }

JNightRider avatar Jun 08 '25 21:06 JNightRider