【发布时间】:2014-08-15 00:34:01
【问题描述】:
我正在将加载图像作为纹理上传到 GLSurfaceView。 生成的纹理在某些设备上看起来非常好,而在其他设备上则显得完全扭曲。
这是三星 Galaxy Nexus(屏幕密度 2.0)上的样子:
摩托罗拉(屏幕密度 1.5)上的相同图像:
这是我的加载代码:
FutureTask<Integer> futureTask = new FutureTask<Integer>(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
// Generate Texture
int[] texturenames = new int[1];
GLES20.glGenTextures(1, texturenames, 0);
// Bind texture to texturename
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texturenames[0]);
// Set filtering
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
GLES20.GL_LINEAR);
// Set wrapping mode
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
// Correct the bitmap if its not a power of two
Bitmap potTextureBitmap = textureBitmap;
int potWidth = nextPOT(textureBitmap.getWidth());
int potHeight = nextPOT(textureBitmap.getHeight());
if ((textureBitmap.getWidth() != potWidth) || (textureBitmap.getHeight() != potHeight)) {
potTextureBitmap = Bitmap.createScaledBitmap(textureBitmap, potWidth, potHeight, false);
}
// Load the bitmap into the bound texture.
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, potTextureBitmap, 0);
GLES20.glFlush();
return Integer.valueOf( texturenames[0]);
}
});
this.mSurfaceView.queueEvent(futureTask);
我做错了什么?
【问题讨论】:
标签: android opengl-es textures