Skip to content

Java\Kotlin tool for managing OpenGL contexts and windows

License

Notifications You must be signed in to change notification settings

husker-dev/grapl

Repository files navigation

boosty

boosty

About

Java\Kotlin tool for managing OpenGL contexts and windows.

Dependency

dependencies {
    implementation 'com.huskerdev:grapl-gl:2.2.0'
}

Available modules:

  • grapl - core library
    • grapl-native-core-win
    • grapl-native-core-macos
    • grapl-native-core-linux
  • grapl-gl - OpenGL module
    • grapl-native-gl-win
    • grapl-native-gl-macos
    • grapl-native-gl-linux
  • grapl-ext-display - Display extension

Usage

Grapl can oparate OpenGL contexts separatly from window

Contexts

  • val context = GLContext.create(..)

    Creates new opengl context with requesterd parameters (doesn't make current)

    • shareWith - Shared context handle
      • type: GLContext/Long
      • default: 0L
    • coreProfile - Core/Compatibility profile
      • type: GLProfile
      • default: GLProfile.CORE
    • majorVersion - Requested major version
      • type: Int
      • default: -1
    • minorVersion - Requested minor version
      • type: Int
      • default: -1
  • context.makeCurrent()

    Makes context current in running thread

  • context.delete()

    Deletes context (does not require to be current)

Windows

Example usage:

GLWindow().apply {
    title = "My application"
    size = 100 x 100
    alignToCenter()

    eventConsumer = windowEventConsumer {
        onInit {
            swapInterval = 1
            GL.createCapabilities()
            glClearColor(1f, 0f, 1f, 1f)
        }
        onUpdate {
            glClear(GL_COLOR_BUFFER_BIT)
            swapBuffers()
        }
    }

    keyTypedListeners += { e ->
        println("key typed: ${e.key.char}")
    }

    visible = true
}

To take control of window event handling:

// Disable built-in message handling
BackgroundMessageHandler.useHandler = false

val window = GLWindow().apply {
    size = 100 x 100
    alignToCenter()
    visible = true
}

// Handle events
while(!window.shouldClose)
    Window.waitMessages() // or peekMessages