Reputation: 1286
I had implemented the possibilty for multiple textures for while now... but yesterday I found out that they won't work as expected on other devices... not mine.. :/ On my device (Experia Mini Pro) it works perfect:
First some code-snippets for loading the texture:
int[] textureID = new int[1];
GLES20.glDeleteTextures(1,textureID,0);
GLES20.glGenTextures(1,textureID,0);
this.unit = textureID[0];
GLES20.glActiveTexture(GLES20.GL_TEXTURE0+this.unit);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,this.unit);
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.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_S,GLES20.GL_REPEAT);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,GLES20.GL_TEXTURE_WRAP_T,GLES20.GL_REPEAT);
...
... bitmap loading functions
...
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D,0,bitmapTexture,0);
bitmapTexture.recycle();
and here the part where my triangles are drawn:
GLES20.glUniform1i(LLShader.location[20],gfx.imagetexture.unit);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0+gfx.imagetexture.unit);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,gfx.imagetexture.unit);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES,0,gfx._vertexBuffer.capacity()/3);
On ym device everything works quite perfect: There are 4 quads, each of them with its own textureunit is drawn one after another.
But then I gave the apk to a friend of mine and on his device (Samsung Galaxy S1) it seems, that it only loads one texture and display only the first of them two... Don't know where to look for.... I didn't find the bug till yet.
PS: Another bug occured, that I don't know to handle. After "reopening" (going from sleepmode) the currently running application all images that should use alpha-blending are black... what could be the Problem ?
Upvotes: 0
Views: 655
Reputation: 1286
Sorry for let you waiting first :/
I scale each texture up to a pow2 sized texture, by looking up when the new pow2-texture is big enough to contain the original bitmap.
When I change the TextureParameterf to GL_CLAMP ... it looks like this:
it seems that one part of the texture-coordinates is not passed right
I hope you know why this looks a little bit weird now.
EDIT: Finally I found out what my failure was. The V-coordinate was not calculated correct. Now, since all v-coordinates are positive, it works fine, thanks :)
Upvotes: 0
Reputation: 3577
This is very similar to another case I worked on just few hours ago.
In OpenGL ES 2.0, in case of no-power of 2 textures, the wrap mode can only be GL_CLAMP_TO_EDGE.
This mean that, if you use a wrap mode different than GL_CLAMP_TO_EDGE it expects to have a power of 2 texture. (for instance, 512X256, 1024X1024 etc).
The interpretation of this rule is quite open and it changes a lot depending on the device, for instance on my Motorola Defy it works, on the Galaxy TAB it does not, this could justify the behavior your are experiencing.
Try this:
20.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);
I hope it will do the magic.
Maurizio Benedetti
Upvotes: 4