Skip to content

xpenatan/gdx-teavm

Repository files navigation

gdx-teavm

Build Build Sonatype Nexus (Snapshots) Static Badge

gdx-teavm is a backend solution for running libGDX games directly in web browsers. It leverages TeaVM, a tool that compiles Java or Kotlin bytecode into JavaScript, enabling seamless execution of game logic within the browser environment without needing additional plugins or complex setup. Additionally, gdx-teavm incorporates Emscripten to handle some of the Java Native Interface (JNI) code, allowing for the execution of specific internal functions that require native performance.

Note:

  • Reflection support is very small so only reflection used in tests will work.
  • TeaVM does not support every class methods from java package or JNI native methods. Check teaVM java classes here.

TeaVM Examples:

TeaVM Games:

LibGDX Supported Versions:

teavm-backend LibGDX
1.0.5 1.12.1
1.1.0 1.13.1

Setup:

// Add sonatype repository to Root gradle
repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "https://oss.sonatype.org/content/repositories/releases/" }
    maven { url "https://teavm.org/maven/repository/" }
    
    // If there is a problem with the teavm repository, you can try using http
    maven {
        url = uri("http://teavm.org/maven/repository/")
        isAllowInsecureProtocol = true
    }
}

// Version
gdxTeaVMVersion = "-SNAPSHOT"
gdxTeaVMVersion = "[LAST_TAG_VERSION]"

// In teaVM module
dependencies {
    implementation "com.github.xpenatan.gdx-teavm:backend-teavm:$project.gdxTeaVMVersion"

    // FreeType extension
    implementation "com.github.xpenatan.gdx-teavm:gdx-freetype-teavm:$project.gdxTeaVMVersion"
}

Supported libraries:

ImGui, Box2D, Bullet, PhysX, and Lua libraries leverage Emscripten and jParser to convert C++ code to JavaScript/WebAssembly.

Important Note: Most of these projects are still works in progress and not yet production-ready. If you're interested in contributing, we welcome your involvement.