An open API service indexing awesome lists of open source software.

https://github.com/husker-dev/grapl

Java\Kotlin tool for managing OpenGL contexts and windows
https://github.com/husker-dev/grapl

Last synced: 3 months ago
JSON representation

Java\Kotlin tool for managing OpenGL contexts and windows

Awesome Lists containing this project

README

          

boosty


boosty


# About

Java\Kotlin tool for managing OpenGL contexts and windows.

- [Dependency](#dependency)
- [Usage](#usage)
- [Contexts](#contexts)
- [Windows](#windows)

# Dependency
```groovy
dependencies {
implementation 'com.huskerdev:grapl-gl:2.3.14'
}
```

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

- ```kotlin
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

- ```kotlin
context.makeCurrent()
```
Makes context current in running thread

- ```kotlin
context.delete()
```
Deletes context (does not require to be current)

## Windows

Example usage:
```kotlin
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:
```kotlin
// 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

```