Virtual Reality (VR)

libGDX can be used to render to virtual reality headsets using LWJGL’s OpenVR (HTC Vive) and OVR (Oculus) modules.

Required Dependencies

The Maven coordinates can be found using the LWJGL customize page.

Example code

Example code can be found at

Additionally, the following demos from LWJGL may be useful for debugging:

Also, see

OpenVR with offscreen GLFW window

Using an offscreen GLFW window allows to render to VR without rendering or maintaining a window on the monitor’s screen. This will allow achieving the fastest performance with OpenVR.

This isn’t supported yet by libGDX, because some hacking is required, but the general flow is the following.

errorCallback = GLFWErrorCallback.createPrint(System.err);
if (!GLFW.glfwInit())
   throw new RuntimeException("Unable to initialize GLFW");
windowHandle = GLFW.glfwCreateWindow(640, 480, "", MemoryUtil.NULL, MemoryUtil.NULL);

Gdx.gl30 = new Lwjgl3GL30(); = Gdx.gl30;
Gdx.gl20 = Gdx.gl30;
Gdx.files = new Lwjgl3Files(); = <minimal implementation of Graphics interface> = <minimal implementation of Application interface>

// setup a scene and model batch

while (running) // See
   // OpenVR waitGetPoses();
   // OpenVR poll events
   // OpenVR Submit eyes
errorCallback = null;


VR support might become easier relatively soon via the use of OpenXR. The LWJGL project plans to support this in the future. This would remove the need to support both OVR and OpenVR and instead just using OpenXR to support all hardware.