OpenGL ES black texture on Nexus S

感情迁移 提交于 2019-12-05 07:22:50
Daniel Smith

The accepted answer given here addresses this issue in slightly more depth than I will, but while this black screen issue does arise from the Nexus S (and some other devices) being strict about power-of-two textures, it does not mean that textures need to have dimensions that are a Po2.

In the texture loading code, one may have the following lines:

        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);

and if this code is modified to add two more lines for clamping, then the phone will support nPo2 textures provided one is ok with clamping. Here is the code with the added clamping:

        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);
        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);

Nexus S is more strict about the size of images that are used as textures in OpenGL ES.

Textures must be a size of 2^n (eg 256, 512, 1024 etc)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!