Log in or register to post comments

Texture is black when rendering

October 7, 2012 - 10:57pm #1

hi,
I use the same code and launch on two devices (one is android smart phone, the other is android tablet PC)

I load texture from website (2D image)
on the smartphone ,it works correct,the texture is rendered
but on the tablet PC it shows black picture
I don't know why and I can't find any error LOG or exception
Does anyone know what should I do?
  please help me
thanks. 

Texture is black when rendering

August 13, 2016 - 3:08am #6

Hi! I just solved this problem and I'd like to share my methods with you. The key problem is not about the texture size( it doesn't need to be size of power of 2).

I worked on the ImageTargets sample, and I needed to get dynamic textures from a server through TCP link. After I dynamically load the texture into mTexture in ImageTarget.java like this( I referred to the loadTextureFromApk() function and wrote the loadTextureFromByteArray() function ):

            mTextures.set(0,Texture.loadTextureFromByteArray(buffer,offset,texLen));

I added the following codes into the begining of renderFrame() function in ImageTargetRenderer.java, to generate a new texture and bind it to GLES20.GL_TEXTURE_2D, and it worked! 

            GLES20.glGenTextures(1, mTextures.get(0).mTextureID, 0);

            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(0).mTextureID[0]);

            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,

                    GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

            GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,

                    GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

            GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA,

                    mTextures.get(0).mWidth, mTextures.get(0).mHeight, 0, GLES20.GL_RGBA,

                    GLES20.GL_UNSIGNED_BYTE, mTextures.get(0).mData);

Before that, I tried to call initRendering() after the texture is loaded, but it didn't work. I also tried to change my texture into 512*512 size, which didn't work either.

I've been searching for the solution for almost two days and finally I fixed it with myself! Hope this can help you. 

This solution may cost lots of CPU time and I'm looking for a faster solution.

Texture is black when rendering

April 21, 2013 - 8:23am #5

Thanks lashman3 for this note.

However, be aware that glEnable(GL_LIGHTING) can only be used with OpenGL ES 1.1, but not on OpenGL ES 2.0, as in the latter case lighting is fully controlled at Shader level (and GL_LIGHTING is not supported).

 

 

Texture is black when rendering

April 21, 2013 - 6:55am #4

it may be that you haven't enabled lighting for open gl es.

try enabling lighting with a call to glEnable;

glEnable(GL_LIGHTING);

 

 

Texture is black when rendering

October 8, 2012 - 12:52am #3

thanks for your reply,
I will try it  

Texture is black when rendering

October 8, 2012 - 12:03am #2

What is the size of the image you are loading?

One possible issue could be if that your image is not a power-of-two sized image, then it may not work with OpenGL ES on some devices; to be on the safe side, you should use power-of-two sized textures (e.g. 256 x 256, or 256 x 128, etc.)

 

Log in or register to post comments