Christopher Porto
07/10/2022, 3:35 AMNo context is current or a function that is not available in the current context was called. The JVM will abort execution.
I'm sure this is due to some threading done underneath and was wondering if there was a way around it. I'll post code in thread. I'm not tied to using LWJGL or AWT, I simply wish to utilize OpenGL within Compose š@Composable
@Preview
fun App() {
MaterialTheme {
Column(Modifier.fillMaxSize(), Arrangement.spacedBy(5.dp)) {
Button(onClick = {}) {
Text("Hello")
}
LwjglExample()
}
}
}
@Composable
@Preview
fun LwjglExample() {
SwingPanel(
background = Color.Black,
modifier = Modifier.size(200.dp, 200.dp),
factory = {
val data = GLData().apply {
majorVersion = 3
minorVersion = 3
profile = GLData.Profile.CORE
samples = 4
}
object : AWTGLCanvas(data) {
override fun initGL() {
createCapabilities()
glClearColor(0.3f, 0.4f, 0.5f, 1F)
}
override fun paintGL() {
val w = 200
val h = 200 // TODO: Remove magic numbers
val aspect = w.toFloat() / h
val now = System.currentTimeMillis() * 0.001
val width = abs(sin(now * 0.3)).toFloat()
glClear(GL_COLOR_BUFFER_BIT)
glViewport(0, 0, w, h)
glBegin(GL_QUADS)
glColor3f(0.4f, 0.6f, 0.8f)
glVertex2f(-0.75f * width / aspect, 0.0f)
glVertex2f(0f, -0.75f)
glVertex2f(+0.75f * width / aspect, 0f)
glVertex2f(0f, +0.75f)
glEnd()
swapBuffers()
}
}
},
update = {
val renderLoop: Runnable = object : Runnable {
override fun run() {
if (!it.isValid) return
it.render()
SwingUtilities.invokeLater(this)
}
}
SwingUtilities.invokeLater(renderLoop)
}
)
}
Michael Paus
07/10/2022, 7:05 AMChristopher Porto
07/10/2022, 11:45 AM