Skip to content
Discussion options

You must be logged in to vote

I solved it as follows

private fun createTextureFromBitmap(engine: Engine, bitmap: Bitmap): Texture {
    val texture = Texture.Builder()
        .width(bitmap.width)
        .height(bitmap.height)
        .levels(1)
        .sampler(Texture.Sampler.SAMPLER_2D)
        .format(Texture.InternalFormat.SRGB8_A8)
        .build(engine)

    val buffer = ByteBuffer.allocateDirect(bitmap.byteCount)
    bitmap.copyPixelsToBuffer(buffer)
    buffer.flip()
    texture.setImage(
        engine, 0, Texture.PixelBufferDescriptor(
            buffer,
            Texture.Format.RGBA,
            Texture.Type.UBYTE
        )
    )
    buffer.clear()
    return texture
}

texture = createTextureFromBitma…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ThomasGorisse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #433 on May 27, 2024 10:15.