Skip to content

Instantly share code, notes, and snippets.

@crykn
Last active October 17, 2022 06:06
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crykn/eb37cb4f7a03d006b3a0ecad27292a2d to your computer and use it in GitHub Desktop.
Save crykn/eb37cb4f7a03d006b3a0ecad27292a2d to your computer and use it in GitHub Desktop.
How to switch to libGDX's LWJGL3 backend

How to switch your libGDX project to LWJGL 3


--- This guide is now available on libgdx.com. Check it out here. If you have any questions, join us on Discord! ---


  1. To switch to libGDX's LWJGL 3 backend, open your root build.gradle file and replace the LWJGL backend dependency:
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"

with the LWJGL 3 backend dependency:

api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"

Make sure to refresh your Gradle dependencies in your IDE.

  1. Next, you need to fix up your DesktopLauncher class. It is located in your desktop project and should look something like this:
public class DesktopLauncher {
   public static void main (String[] arg) {
      LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
      new LwjglApplication(new MyGdxGame(), config);
   }
}

You’ll need to change it to this:

public class DesktopLauncher {
   public static void main (String[] arg) {
      Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
      new Lwjgl3Application(new MyGdxGame(), config);
   }
}

Common issues:

  • On macOS, the LWJGL 3 backend is only working when the JVM is run with the -XstartOnFirstThread argument. This can typically be done in the Launch/Run Configurations of your IDE. Further information can be found here.
  • If you are using gdx-tools and the lwjgl3 backend in the same project, you need to modify your gdx-tools dependency like this:
    compile ("com.badlogicgames.gdx:gdx-tools:$gdxVersion") {
       exclude group: 'com.badlogicgames.gdx', module: 'gdx-backend-lwjgl'
    }
    
    The cause of this is described here.
@megalithic3
Copy link

Running Android Studio v4.0.1 on Win 10 64 bit machine.

What does it mean to "Make sure to refresh your Gradle dependencies in your IDE."

I made the 2 changes above to my build.gradle and DesktopLauncher.
I invalidated caches and restarted, cleaned and rebuilt project.
I get this error and others when trying to launch desktop.
"Could not find lwjgl-glfw-3.2.3-natives-sindows-x86.jar (org.lwjgl:lwjgl-glfw:3.2.3)"

@megalithic3
Copy link

typo "windows' not "sindows"
lwjgl-glfw-3.2.3-natives-windows-x86.jar (org.lwjgl:lwjgl-glfw:3.2.3)

@crykn
Copy link
Author

crykn commented Sep 26, 2021

What does it mean to "Make sure to refresh your Gradle dependencies in your IDE."

That depends on your IDE. In IntelliJ or AndroidStudio, right-click the project name in the Gradle Tool Window -> Refresh dependencies. In Eclipse, right-click the build.gradle file (in the desktop project) -> Gradle -> Refresh Dependencies. For further questions, the libGDX Discord is probably the better place.

@BrownCoatJustice
Copy link

What do you mean by:

On macOS, the LWJGL 3 backend is only working when the JVM is run with the -XstartOnFirstThread argument. This can typically be done in the Launch/Run Configurations of your IDE.

Do you mean by adding -XstartOnFirstThread in the VM arguments?

@crykn
Copy link
Author

crykn commented Jan 23, 2022

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment