javanvidialwjglarchlinuxwayland

glfwCreateWindow fails on Wayland (Hyprland, NVIDIA): EGL context error


I'm trying to create a GLFW window through LWJGL using Hyprland (Wayland) as window manager on Arch Linux. The application fails with the following message:

[LWJGL] GLFW_PLATFORM_ERROR error
  Description : 
    EGL: Failed to clear current context: 
    An EGLDisplay argument does not name a valid EGL display connection

    Stacktrace  :
      org.lwjgl.glfw.GLFW.nglfwCreateWindow(GLFW.java:2086)
      org.lwjgl.glfw.GLFW.glfwCreateWindow(GLFW.java:2251)

Environment

OS: Arch Linux (6.12.9-arch-1)

Compositor: Hyprland (Wayland)

GPU: NVIDIA RTX 3070

Driver Version: 565.77

LWJGL Version: 3.3.6

EGL Version: 1.5


Reproduce

import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;

import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;

public class Game {
    public static void main(String[] args) {
        GLFWErrorCallback.createPrint(System.err).set();

        if (!glfwInit()) 
            throw new IllegalStateException("Unable to init GLFW");

        glfwDefaultWindowHints();
        glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
        glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
        glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);

        long window = glfwCreateWindow(800, 600, "Test", NULL, NULL);
        if (window == NULL) 
            throw new RuntimeException("glfwCreateWindow failed");

        glfwMakeContextCurrent(window);
        glfwSwapInterval(1);
        glfwShowWindow(window);
    }
}

LWJGL

Used imports from here (stable 3.3.6 Linux x86, full)


PS I tried running vkcube, glxgears, weston and own vulkan renderer with winit in Rust - all worked fine.


Solution

  • Put as the first line of code in your main() function:

    if(glfwPlatformSupported(GLFW_PLATFORM_WAYLAND)) glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND);