[英]Cubemap texture with bitmap in OpenGL ES 2.0/3.0
When I create a cubemap texture with simple colors, this works well:当我使用简单的 colors 创建立方体贴图纹理时,效果很好:
@JvmStatic
fun createSimpleTextureCubemap() {
val textureId = IntArray(1)
val cubeFace0 = byteArrayOf(127, 127, 127)
val cubeFace1 = byteArrayOf(0, 127, 0)
... // create other cube faces with simple color
val cubeFaces = ByteBuffer.allocateDirect(3)
glGenTextures(1, textureId, 0)
glBindTexture(GL_TEXTURE_CUBE_MAP, textureId[0])
cubeFaces.put(cubeFace0).position(0)
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB,
1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, cubeFaces)
cubeFaces.put(cubeFace1).position(0)
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB,
1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, cubeFaces)
...
return textureId[0]
}
But when I try to create a cubemap texture with bitmap:但是当我尝试使用 bitmap 创建立方体贴图纹理时:
@JvmStatic
fun createTextureCubemap(context: Context, rowID: Int) {
val input = context.resources.openRawResource(rowID)
val bitmap = BitmapFactory.decodeStream(input)
val textureId = IntArray(1)
glGenTextures(1, textureId, 0)
glBindTexture(GL_TEXTURE_CUBE_MAP, textureId[0])
GLUtils.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, bitmap, 0)
GLUtils.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, bitmap, 0)
GLUtils.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, bitmap, 0)
GLUtils.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, bitmap, 0)
GLUtils.texImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, bitmap, 0)
GLUtils.texImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, bitmap, 0)
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
return textureId[0]
}
Then the object turns black.然后 object 变黑。 Someone may suggest why the cubemap with the bitmap does not work (black color)?
有人可能会建议为什么带有 bitmap 的立方体贴图不起作用(黑色)?
Thanks for any comment/answer.感谢您的任何评论/回答。
Textures for Cubemaps need to be square.立方体贴图的纹理需要是方形的。 As mentioned in the comments, the bitmap used was not square.
正如评论中提到的,使用的 bitmap 不是方形的。
From glTexImage2D reference ( GLUtils.texImage2D
is a convenience wrapper around glTexImage2D
)来自glTexImage2D 参考(
GLUtils.texImage2D
是glTexImage2D
的便利包装)
GL_INVALID_VALUE is generated if target is one of the six cube map 2D image targets and the width and height parameters are not equal.
如果目标是 6 个立方体 map 2D 图像目标之一并且宽度和高度参数不相等,则会生成 GL_INVALID_VALUE。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.