【问题标题】:OpenGL Textures have distorted colors on some android devicesOpenGL 纹理在某些 Android 设备上出现颜色失真
【发布时间】: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


    【解决方案1】:

    我终于找到了这个问题的原因。 它相当具体,但无论如何我都会分享细节:

    我的颜色计算出现错误。我需要将十六进制颜色转换为标准化 rgba(在我的情况下将白色 #ffffffff 转换为 {1.0, 1.0, 1.0, 1.0}),但实际上我将非标准化值输入到我的着色器中(例如:{255, 255, 255, 255})。 当与我的纹理中的颜色相乘时,产生的颜色会爆炸。 根据显卡的不同,这是否会导致伪影。 因此,假设对屏幕分辨率的依赖纯属巧合!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-13
      • 2012-09-14
      相关资源
      最近更新 更多