LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.73k stars 632 forks source link

GL.create() assumes GLX on Linux #748

Open asdfjkluiop opened 2 years ago

asdfjkluiop commented 2 years ago

Version

3.3.0 (nightly)

Platform

Linux x64

JDK

Eclipse OpenJ9 VM 17.0.2.0

Module

OpenGL

Bug description

GL.create() assumes GLX on Linux using libGL.so and glXGetProcAddress(). The problem with this is libGL.so isn't always available on wayland platforms causing LWJGL initialization to fail. I ran into this bug on a fresh debian install where the only thing installed was the sway wayland compositor. libEGL is present but not libGL since wayland uses EGL for context management. My game engine works around this by setting Configuration.OPENGL_EXPLICIT_INIT.set(true) and then using GL.create(GLFW::glfwGetProcAddress) since GLFW uses the API for context creation to implement that function however LWJGL's automatic extension loading should avoid making assumptions about what windowing system is being used as it can break in some cases. To be honest I don't know what a good fix for this is besides just leaving it to the engine/game but I figured I'd bring it up in case anyone had a solution that could be put into LWJGL.

Stacktrace or crash log output

No response

Spasi commented 2 years ago

Hey @asdfjkluiop,

That is indeed true, the GL class assumes GLX on Linux. However, LWJGL has EGL bindings and GLFW supports EGL (see GLFW_EGL_CONTEXT_API). On Wayland, I believe the correct approach would be:

Configuration.OPENGL_EXPLICIT_INIT.set(true);
GL.create(EGL.getFunctionProvider());

and then you would proceed with the usual GLFW setup.