【发布时间】:2020-08-02 23:58:45
【问题描述】:
我需要一个 Android 应用程序中的 8x8x8 LED 立方体。我找到了一个 OpenGL 教程,它有这个 led 立方体,但它在纹理上使用了位图。我可以把它改成简单的颜色吗?纹理助手是这样的:
fun loadTexture(context: Context, resourceId: Int): Int {
val textureHandle = IntArray(1)
GLES20.glGenTextures(1, textureHandle, 0)
if (textureHandle[0] == 0) {
throw RuntimeException("Error generating texture name.")
}
val options = BitmapFactory.Options()
options.inScaled = false // No pre-scaling
// Read in the resource
val bitmap = BitmapFactory.decodeResource(context.resources, resourceId, options)
// Bind to the texture in OpenGL
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0])
// Set filtering
GLES20.glTexParameteri(
GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER,
GLES20.GL_NEAREST
)
GLES20.glTexParameteri(
GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER,
GLES20.GL_NEAREST
)
// Load the bitmap into the bound texture.
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0)
// Recycle the bitmap, since its data has been loaded into OpenGL.
bitmap.recycle()
return textureHandle[0]
}
【问题讨论】:
标签: android opengl-es-2.0