KorGE Game Engine

repository·main·Indexed 23 days ago

https://github.com/korlibs/korge

A modern, 100% Kotlin multiplatform game engine supporting Android, Web (JS/WASM), iOS, and Desktop. It features hot reloading, live debugging, and includes Korui for multiplatform UI development. The engine utilizes Korag (Kotlin cORoutines Accelerated Graphics) for a unified API across WebGL, AWT+OpenGL, and GL|es Android, providing a DSL for building shaders and an AG API for accelerated graphics.

Tokens
3.7K
Snippets
5
Records
37
Agent score
84%

What's inside KorGE

  1. Use Korag for accelerated graphics

    main

    Korag (Kotlin cORoutines Accelerated Graphics) provides a unified API for accelerated graphics across multiple backends including WebGL, AWT+OpenGL, and GL|es Android. It supports OpenGL, WebGL, Stage3D, DirectX, Vulkan, and Metal.

    Korag provides an AST for Shaders and a DSL for building them in code.

  2. Use KorGE from source in other projects

    main

    To use the current development version of KorGE in your own projects, you can publish it to your local Maven repository using the following command:

    ./gradlew publishToMavenLocal
  3. Run the KorGE sandbox for experimentation

    main

    If you want to experiment with changes or test code within the KorGE repository, you can run the korge-sandbox module. This module executes the src/commonMain/kotlin/Main.kt file across different platforms.

    ./gradlew :korge-sandbox:runJvm
    ./gradlew :korge-sandbox:runJs
    ./gradlew :korge-sandbox:runAndroidRelease
    ./gradlew :korge-sandbox:runIosDeviceRelease
  4. Install and use KorGE

    main

    KorGE is a multiplatform game engine for Kotlin. You can get started quickly using one of the following methods:

    1. KorGE Forge: Install KorGE Forge for an integrated experience.
    2. Clone a Template: Clone the "Hello World!" project to start developing immediately.

    KorGE supports multiple platforms via its Gradle plugin:

    • Android: JVM
    • Web: JS & WASM
    • iOS: Native code
    • Desktop: JVM/JS
  5. Draw a triangle with Korag

    main

    To draw a basic shape like a triangle using a predefined shader, vertex attribute layout, and a Matrix4 uniform, use the AG API.

    Example of drawing a red triangle on a blue background:

    ag.clear(Colors.BLUE)
    ag.createVertexBuffer(floatArrayOf(
      0f, 0f,
      640f, 0f,
      640f, 480f
    )).use { vertices ->
        ag.draw(
            vertices,
            program = DefaultShaders.PROGRAM_DEBUG_WITH_PROJ,
            type = AGDrawType.TRIANGLES,
            vertexLayout = DefaultShaders.LAYOUT_DEBUG,
            vertexCount = 3,
            uniforms = mapOf(
                DefaultShaders.u_ProjMat to Matrix4().setToOrtho(0f, 0f, 640f, 480f, -1f, +1f)
            )
        )
    }
  6. AG API Reference

    main

    The AG class is the primary interface for accelerated graphics.

    Key Methods

    • clear(color, depth, stencil, clearColor, clearDepth, clearStencil): Clears the background.
    • createVertexBuffer(data: FloatArray, ...): Creates a vertex buffer.
    • createTexture(bmp: Bitmap, ...): Creates a texture from a bitmap.
    • draw(vertices, program, type, vertexLayout, vertexCount, ...): Draws geometry using a specific program and layout.
    • renderToTexture(width, height, callback): Renders content to a RenderTexture.

    Inner Classes

    • AG.Texture: Represents a GPU texture. Supports upload(bmp) and close().
    • AG.Buffer: Represents a vertex or index buffer. Supports upload(data) for various types (FloatArray, IntArray, etc.).
    • AG.RenderTexture: Contains a Texture, width, and height.
    • AG.DrawType: Enum for drawing modes (e.g., TRIANGLES).
  7. Define custom shader elements and programs

    main

    You can define your own shader components using the Korag DSL.

    Defining Elements

    val u_Tex = Uniform("u_Tex", VarType.TextureUnit)
    val u_ProjMat = Uniform("u_ProjMat", VarType.Mat4)
    val a_Pos = Attribute("a_Pos", VarType.Float2, normalized = false)
    val LAYOUT_DEFAULT = VertexLayout(a_Pos, a_Tex, a_Col)

    Defining a Program with DSL

    val PROGRAM_DEBUG_WITH_PROJ = Program(
    	vertex = VertexShader {
    		SET(out, u_ProjMat * vec4(a_Pos, 0f.lit, 1f.lit))
    	},
    	fragment = FragmentShader {
    		SET(out, vec4(1f.lit, 0f.lit, 0f.lit, 1f.lit))
    	}
    )
  8. Migrate to the new KorGE Maven namespace

    main

    As of May 2026, KorGE has moved from the com.soywiz.korge namespace to org.korge. This is a breaking change. You must update your dependency configurations (e.g., in gradle/libs.versions.toml) to use the new namespace. To use the latest snapshot version, update your plugin definition as shown below.

    [plugins]
    #korge = { id = "com.soywiz.korge", version = "6.0.0" }   <-- Old namespace, latest official version
    korge = { id = "org.korge.engine", version = "7.0.0-SNAPSHOT" }   # <-- New namespace, use latest snapshot version
  9. DefaultShaders Reference

    main

    DefaultShaders provides pre-defined shader elements and programs for quick use:

    • u_Tex: Texture Uniform
    • u_ProjMat: Projection Matrix Uniform
    • a_Pos: Position Attribute (float, float)
    • a_Tex: Texture Coordinate Attribute (float, float)
    • a_Col: Color Attribute (int)
    • LAYOUT_DEFAULT: VertexFormat using a_Pos, a_Tex, a_Col
    • PROGRAM_DEBUG_WITH_PROJ: A debug program that accepts a projection matrix.
    • PROGRAM_DEFAULT: The default program.