android opengl texture 的一个有趣现像
下载到Cube_OpenGL,在模拟器上运行正常,但在手机上却显示不出texture。
发现原程序如下位置有问题,
gl.glGenTextures(6, tmp_tex, 0);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
for (int i = 0; i < 6; i++)
{
gl.glBindTexture(GL10.GL_TEXTURE_2D, tmp_tex[i]);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp[i], 0);
}
实际应该如下
gl.glGenTextures(6, tmp_tex, 0);
for (int i = 0; i < 6; i++)
{
gl.glBindTexture(GL10.GL_TEXTURE_2D, tmp_tex[i]);
// !!! originally, the following two lines are behind glGenTextures, that should not work,
// however it works on emulators
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
//gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp[i], 0);
}