Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/LWJGL/lwjgl3/llms.txt

Use this file to discover all available pages before exploring further.

LWJGL 3 includes Khronos bindings for GPU compute, augmented and virtual reality, and low-level rendering surface management. These bindings target specialized workloads — parallel computation on heterogeneous hardware, immersive XR experiences, and platform-neutral surface creation — that sit alongside the main graphics pipeline.
The current stable release is 3.4.2. All bindings listed here are optional modules. Use the LWJGL build configurator to generate Maven or Gradle dependency declarations.

OpenCL

Maven artifact: org.lwjgl:lwjgl-opencl
Key classes: CL10, CL11, CL12, CL20, CL21, CL30, CLPlatform, CLDevice, CLContext, CLCommandQueue, CLKernel
OpenCL is an open, royalty-free standard for cross-platform, parallel programming of diverse processors — CPUs, GPUs, DSPs, and FPGAs. LWJGL exposes the full OpenCL specification through per-version classes (CL10 through CL30), giving you direct, high-performance access to every entry point. OpenCL object model:
ObjectPurpose
CLPlatformRepresents an OpenCL implementation (e.g., the NVIDIA or Intel driver)
CLDeviceAn individual compute device (GPU, CPU, accelerator)
CLContextManages a set of devices and their shared memory objects
CLCommandQueueSubmits commands (kernel dispatches, memory transfers) to a device
CLProgram / CLKernelCompiled OpenCL C source and an individual kernel entry point
CLMemDevice-side memory buffer or image object
Version coverage:
ClassStandardNotable additions
CL10OpenCL 1.0Core platform, context, queue, buffer, kernel APIs
CL11OpenCL 1.1Sub-buffers, user events, clSetMemObjectDestructorCallback
CL12OpenCL 1.2clCompileProgram, clLinkProgram, partitioned devices, image arrays
CL20OpenCL 2.0Shared virtual memory (SVM), device-side enqueue, pipes
CL21OpenCL 2.1SPIR-V ingestion, clGetHostTimer, sub-group queries
CL30OpenCL 3.0Feature queries, cl_khr_extended_versioning
Hello World — vector addition:
// Enumerate platforms and pick the first GPU
CLPlatform platform = CLPlatform.getPlatforms().get(0);
CLDevice device = platform.getDevices(CL10.CL_DEVICE_TYPE_GPU).get(0);

// Create context and command queue
long context = CL10.clCreateContext(null, device, null, NULL, null);
long queue   = CL10.clCreateCommandQueue(context, device, 0, null);

// Compile a kernel from source
String src = "__kernel void add(__global float* a, __global float* b, __global float* c) {"
           + "  int i = get_global_id(0); c[i] = a[i] + b[i]; }";
long program = CL10.clCreateProgramWithSource(context, src, null);
CL10.clBuildProgram(program, device, "", null, NULL);
long kernel = CL10.clCreateKernel(program, "add", null);
OpenCL 2.0+ shared virtual memory (SVM) lets the CPU and GPU share pointer-addressable memory without explicit buffer copies — useful for pointer-heavy data structures like linked lists and trees.
Interoperability with OpenGL and Vulkan: LWJGL supports OpenCL-GL and OpenCL-Vulkan interop extensions. Create an OpenCL context that shares a GL context using KHRGLSharing.clCreateContextFromType(), then acquire and release GL buffer/texture objects in the command queue to avoid redundant data copies between compute and rendering.

OpenXR

Maven artifact: org.lwjgl:lwjgl-openxr
Key classes: XR10, XrInstance, XrSession, XrSpace, XrSwapchain, XrFrameState, XrCompositionLayerProjection
OpenXR is a royalty-free, open standard from Khronos that provides unified access to Augmented Reality (AR) and Virtual Reality (VR) — collectively known as XR — platforms and devices. It replaces proprietary SDKs (Oculus, SteamVR, WMR) with a single API surface. Core XR concepts:
ConceptDescription
XrInstanceConnection to the OpenXR runtime. One per application.
XrSystemThe XR hardware (headset + controllers) attached to the runtime
XrSessionAn active XR experience; manages the frame loop
XrSpaceA frame of reference: stage (room scale), local (seated), or view (HMD)
XrSwapchainA set of GPU-renderable images for one eye (or layer)
XrActionAn abstract input action (grip, trigger, pose) bound to physical controllers
Frame loop structure:
// Per-frame: wait, begin, locate views, render, end
XrFrameState frameState = XrFrameState.calloc(stack);
XR10.xrWaitFrame(session, null, frameState);
XR10.xrBeginFrame(session, null);

// Locate views (eye poses and FOVs)
XrViewState viewState = XrViewState.calloc(stack);
XrView.Buffer views = XrView.calloc(2, stack);
// ... fill viewLocateInfo, call xrLocateViews ...

// Render each eye into swapchain images, then submit
// ... acquire swapchain image, render, release ...

XrFrameEndInfo endInfo = XrFrameEndInfo.calloc(stack)
    .type(XR10.XR_TYPE_FRAME_END_INFO)
    .displayTime(frameState.predictedDisplayTime())
    .environmentBlendMode(XR10.XR_ENVIRONMENT_BLEND_MODE_OPAQUE)
    .layers(layers);
XR10.xrEndFrame(session, endInfo);
Extension support: OpenXR’s extension model mirrors Vulkan’s. Query available extensions with XR10.xrEnumerateInstanceExtensionProperties() and enable them at instance creation. Common extensions include:
ExtensionPurpose
XR_KHR_opengl_enableUse OpenGL as the graphics backend
XR_KHR_vulkan_enable2Use Vulkan as the graphics backend
XR_EXT_hand_trackingPer-joint hand skeleton data
XR_FB_passthroughMixed-reality passthrough camera
XR_MSFT_spatial_anchorPersistent world-locked anchors
Start with the XR_KHR_opengl_enable extension if you already have an OpenGL rendering pipeline. Migrating to XR_KHR_vulkan_enable2 gives lower latency and better reprojection support on most runtimes.

EGL

Maven artifact: org.lwjgl:lwjgl-egl
Key classes: EGL, EGL10, EGL11, EGL12, EGL13, EGL14, EGL15, EGLCapabilities
EGL is the Khronos interface between rendering APIs (OpenGL ES, OpenVG, and, via extensions, desktop OpenGL and Vulkan) and the underlying native platform window system. It handles surface creation, context management, and buffer swapping in a platform-neutral way. Where EGL is used:
PlatformRole
AndroidPrimary window system integration for OpenGL ES
Embedded Linux (without X11/Wayland)Direct framebuffer rendering
Offscreen / headless renderingCreate surfaceless contexts for compute-only or server-side rendering
NVIDIA / Mesa desktopDesktop OpenGL via EGL_KHR_platform_gbm or EGL_KHR_platform_x11
EGL object hierarchy:
EGLDisplay
  └── EGLConfig (surface capabilities: color depth, depth buffer, stencil, MSAA)
        ├── EGLSurface (window surface, pbuffer, or pixmap)
        └── EGLContext (bound to a surface for rendering)
Headless / offscreen context (pbuffer):
long display = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
EGL14.eglInitialize(display, null, 0, null, 0);

int[] attribs = { EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT,
                  EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
                  EGL14.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
EGL14.eglChooseConfig(display, attribs, 0, configs, 0, 1, null, 0);

int[] pbAttribs = { EGL14.EGL_WIDTH, 1920, EGL14.EGL_HEIGHT, 1080, EGL14.EGL_NONE };
EGLSurface surface = EGL14.eglCreatePbufferSurface(display, configs[0], pbAttribs, 0);

int[] ctxAttribs = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 3, EGL14.EGL_NONE };
EGLContext ctx = EGL14.eglCreateContext(display, configs[0], EGL14.EGL_NO_CONTEXT, ctxAttribs, 0);
EGL14.eglMakeCurrent(display, surface, surface, ctx);
On desktop Linux with a display server, GLFW handles EGL internally when you set the GLFW_PLATFORM hint to GLFW_PLATFORM_WAYLAND. Use the bare EGL binding only when you need direct EGL control — for example, in headless server-side rendering or when integrating with a non-GLFW window system.

Choosing a Compute or XR Backend

WorkloadRecommended binding
General-purpose GPU compute (image processing, ML inference, simulation)OpenCL (org.lwjgl:lwjgl-opencl)
Vulkan-native compute shadersVulkan (org.lwjgl:lwjgl-vulkan)
Headset / AR / VR applicationOpenXR (org.lwjgl:lwjgl-openxr)
Headless OpenGL ES (server, CI, embedded)EGL (org.lwjgl:lwjgl-egl)
Embedded platform with no X11/WaylandEGL + OpenGL ES

Build docs developers (and LLMs) love