Jakob K
10/04/2021, 5:43 PMBufferedImage
. As compose-jb can render to a JFrame
, shouldn't this theoretically work?Igor Demin
10/04/2021, 5:46 PMJakob K
10/04/2021, 5:50 PMbut it doesn't support animations/events at the moment.does that mean it crashes when using animations - or are animations just not displayed correctly?
Igor Demin
10/04/2021, 5:52 PMmcpiroman
10/04/2021, 5:52 PMIgor Demin
10/04/2021, 5:52 PMmcpiroman
10/04/2021, 5:54 PMIgor Demin
10/04/2021, 6:02 PMTherefore something like FrameBuffer in OpenGLIt can be done via
ComposeScene
. Just create appropriate Skia Surface, obtain Canvas from it, and call ComposeScene.render(canvas, time)
Skia supports rendering into any graphics context (that it is how we implemented rendering in skiko (1 2))
Also if I could capture the input events at the top levelYes, passing events in pixels also possible:
scene.sendPointerEvent(PointerEventType.Press, Offset(0f, 10f))
After we complete the current rebase to the latest Compose, we will perform a new rebase this or next week which will contain ComposeScene
Igor Demin
10/04/2021, 6:21 PMfixed-size image and then resize and print the image onto the windowNote that the graphic context created inside Skiko for rendering into the default
ComposeWindow
(it is JFrame) isn't available for external usage, so if you need to draw into texture and use it inside the usual ComposeWindow, it doesn't work. You probably need to create your own graphic context and rasterize the graphic buffer into Bitmap.mcpiroman
10/04/2021, 6:27 PMComposeWindow
, once I have the texture it would probably be quite easy to display it natively. Therefore maybe I can avoid creating second skia context, assuming the default one would work.mcpiroman
10/04/2021, 6:28 PMIgor Demin
10/04/2021, 6:32 PMonce I have the texture it would probably be quite easy to display it nativelyYes, if you entirely use your own context for Compose rendering then there is no issue 🙂 . But ComposeScene currently doesn't support some features which is/will be supported by ComposeWindow (Input methods, Accessibility, Pointer icon change). Maybe they aren't so important for a game.
Jakob K
10/22/2021, 5:11 PMNext week there will be ComposeScene for that.so
ComposeScene
is available now :), and I was asking myself how I can read out the RGB values using it
currently I have:
val bitmap = Bitmap()
val canvas = Canvas(bitmap)
val scene = ComposeScene()
scene.setContent { TestComposable() }
scene.render(canvas, System.nanoTime())
and to read the RGB values I tried bitmap.getColor(x, y)
but that always gives me 0
.Igor Demin
10/22/2021, 5:32 PMimport androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.ui.ComposeScene
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import org.jetbrains.skia.Bitmap
import org.jetbrains.skia.Canvas
import org.jetbrains.skia.ColorAlphaType
import org.jetbrains.skia.Image
import org.jetbrains.skia.ImageInfo
import java.io.File
fun main() {
val bitmap = Bitmap()
bitmap.allocPixels(ImageInfo.makeN32(500, 500, ColorAlphaType.PREMUL))
val canvas = Canvas(bitmap)
val scene = ComposeScene()
scene.setContent {
Box(Modifier.size(200.dp, 200.dp).background(Color.Red))
}
scene.render(canvas, System.nanoTime())
File("D:/1.png").writeBytes(Image.makeFromBitmap(bitmap).encodeToData()!!.bytes)
println(Color(bitmap.getColor(0, 0)).red)
}
Jakob K
10/22/2021, 5:36 PMJakob K
10/22/2021, 5:38 PMJakob K
10/22/2021, 9:56 PMFilterQuality.None
in that context?Igor Demin
10/23/2021, 8:49 AMFilterMipmap(FilterMode.NEAREST, MipmapMode.NONE)
when you draw image via drawImageRect
Alternative is to convert Skia Canvas to Compose Canvas: skiaCanvas.asComposeCanvas()
, and just use FilterQuality.None
Jakob K
10/23/2021, 2:53 PMval bitmap = Bitmap()
if (bitmap.allocN32Pixels(blockWidth * 128, blockHeight * 128, false)) {
val canvas = Canvas(bitmap)
val scene = ComposeScene()
scene.setContent { contenthere }
scene.render(canvas, System.nanoTime())
scene.close()
}
Is it possible to disable the effect displayed in the second image in the above code?Igor Demin
10/23/2021, 4:33 PMval canvasWithoutAntialias = object : PaintFilterCanvas(canvas, true) {
override fun onFilter(paint: Paint): Boolean {
paint.isAntiAlias = false
return true
}
}
but it is broken in 1.0.0-beta1 (it worked in 1.0.0-alpha3, you can file a bug in skiko).
and probably doesn't affect text (not sure)Igor Demin
10/23/2021, 4:41 PMMinecraft has anti aliasing by itselfIt applies antialiasing to 3D content, Compose content itself is 2D content, Minecraft doesn't know how to apply antialiasing to it. Not sure, but the only possible way to draw a high quality image in any camera angle is to draw Compose content in a higher resolution with enabled Compose antialiasing.
Jakob K
10/23/2021, 5:56 PMbut it is broken in 1.0.0-beta1 (it worked in 1.0.0-alpha3, you can file a bug in skiko).do I have to file a bug to get this fixed or will it probably be fixed sometime in the future?
Igor Demin
10/23/2021, 6:05 PMJakob K
10/23/2021, 6:12 PM