Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL ES black texture on Nexus S

OpenGL code that works on the Nexus One will not work properly on the Nexus S. Textures don't seem to render and I'm left with just black where textures should be.

Anyone got any ideas?

like image 959
Rab Ross Avatar asked Jan 24 '11 11:01

Rab Ross


1 Answers

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);
like image 69
Daniel Smith Avatar answered Oct 27 '22 13:10

Daniel Smith