This guide walks you through creating a minimal LWJGL 3 application that opens a window using GLFW and sets up an OpenGL context. By the end you will have a working render loop that you can extend with your own drawing code. LWJGL 3.4.2 is the current release.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 is not a framework. It does not manage a game loop, a scene graph, or asset loading for you. What it provides is direct, type-safe access to native libraries — the same APIs you would use from C or C++.
Prerequisites
- JDK 8 or later installed and on your
PATH - A Gradle or Maven project (this guide uses Gradle)
- Basic familiarity with Java
Add dependencies
LWJGL is distributed as a set of modules on Maven Central under the group
org.lwjgl. You always need the core lwjgl artifact plus the binding modules for the APIs you want to use. For each module that has native code, you also need the corresponding natives JAR for your target platform.The example below adds the core module, GLFW, and OpenGL for all three major desktop platforms. If you only need to support one platform you can include a single natives classifier instead.Initialize GLFW and create a window
Before calling any GLFW function you must initialize the library. After initialization you set window hints and then create the window. The
glfwMakeContextCurrent call binds the OpenGL context to the current thread, and GL.createCapabilities() interrogates the driver to expose the available OpenGL functions.HelloWindow.java
Create OpenGL capabilities and render a frame
After binding the context you must call
GL.createCapabilities() so that LWJGL can discover which OpenGL extensions are available on the current driver. You then enter the render loop, which polls for OS events, clears the framebuffer, and swaps the front and back buffers on every iteration.HelloWindow.java (continued)
Clean up resources
LWJGL uses off-heap memory and native handles that the Java garbage collector does not manage. Always clean up in reverse order of creation: release OpenGL capabilities, free GLFW callbacks, destroy the window, and then terminate GLFW.The pattern shown in step 2 — freeing callbacks, destroying the window, and calling
glfwTerminate() — is the correct teardown sequence. In a larger application, consider wrapping initialization in a try/finally block to ensure cleanup runs even if an exception occurs:teardown pattern
What’s next
You now have a working window and OpenGL context. From here you can:- Upload geometry to the GPU using Vertex Buffer Objects (VBOs) — see the OpenGL rendering guide
- Add keyboard, mouse, and gamepad handling — see the windowing with GLFW guide
- Browse the LWJGL sample suite for working examples covering GLFW, OpenGL, Vulkan, and more
See Installation for a complete reference of all available modules, native classifier names, and Maven POM syntax.