有锯齿的圆
解决方案是 smoothstep
。它根据到 texture
与背景的变换起始点的距离平滑的从0
到1
变化。因此距离 0
到 0.49
时 texture
的透明度为 1
,大于等于 0.5
时为 0
,0.49
和 0.5
之间时平滑变化,如此圆的边就平滑了。
无锯齿圆
OpenGL
中如何使用 texture
显示图像和文本?在动画中圆有两种状态 —— 普通和选中。在普通状态下圆的 texture
包含文字和颜色,在选中状态下同时包含图像。因此我需要为每个圆创建两个不同的 texture
。
我使用 Bitmap
实例来创建 texture
,绘制所有元素。
fun bindTextures(textureIds: IntArray, index: Int) {
texture = bindTexture(textureIds, index * 2, false)
imageTexture = bindTexture(textureIds, index * 2 + 1, true)
}
private fun bindTexture(textureIds: IntArray, index: Int, withImage: Boolean): Int {
glGenTextures(1, textureIds, index)
createBitmap(withImage).toTexture(textureIds[index])
return textureIds[index]
}
private fun createBitmap(withImage: Boolean): Bitmap {
var bitmap = Bitmap.createBitmap(bitmapSize.toInt(), bitmapSize.toInt(), Bitmap.Config.ARGB_4444)
val bitmapConfig: Bitmap.Config = bitmap.conf