LWJGL and Supported Resolutions

It would more than likely be a better way to get the supported resolutions from LWJGL. On some systems, notably linux, invalid refresh rates are reported from AWT and results in the window failing to be created. The resolution given to JME is validated against LWJGL, and if no match is found it will reject it. So if we get the resolutions from the LWJGL, we won’t have any issue.

The code snippets below get the resolutions from each:

LWJGL2

DisplayMode[] modes = Display.getAvailableDisplayModes();
 
for (int i=0;i<modes.length;i++) {
    DisplayMode current = modes[i];
    System.out.println(current.getWidth() + "x" + current.getHeight() + "x" +
                        current.getBitsPerPixel() + " " + current.getFrequency() + "Hz");
}

LWJGL3

PointerBuffer monitors = GLFW.glfwGetMonitors();

for ( int i = 0; i < monitors.limit(); i++ ) {
    long monitor = monitors.get(i);

    GLFWVidMode.Buffer modes = GLFW.glfwGetVideoModes(monitor);

    int modeCount = modes.sizeof();

    for ( int j = 0; j < modeCount; j++ ) {
        modes.position(j);

        int width = modes.width();
        int height = modes.height();
        int rate = modes.refreshRate();

         System.out.println("Resolution: " + width + " x " + height + " @ " + rate);

    }
 }

The results can be wrapped to provide an API that returns the same result for both versions.

As far as I’m aware, though, these can’t be run until LWJGL is initialized. Is it possible to initialize LWJGL before the AppSettings dialog is displayed and report the LWJGL resolutions?

4 Likes

So the way I handled it with spoxel was to call glfwInit(), get the resolution information and then call glfwTerminate() inside my launcher. This allowed me to get the correct resolutions before the jme windowed is actually created or displayed.

2 Likes

Someone remind me on discord later today to check how we did this for lightspeed frontier, please. If I remember correctly we wrote our custom launcher which completely replaced the jme’s app settings window.