Hello all,
If I set the texture before hand, the texture loads correctly. For
that I used the following code I found in one of the open gl es
samples (TriangleRenderer).
...
InputStream is = mContext.getResources().openRawResource(mTexture);
Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources
(),mTexture);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
...
BUT, I want to be able to apply different textures to different
models. My problem is that I'm trying to load a texture to map to my
model, but the texture is coming out in a shade of blue. It looks
almost like i'm looking at my object through a blue tinted window. I'm
not sure why this is the case.
Here is my code for loading the texture:
protected static int loadTexture(GL10 gl, Bitmap bmp) {
ByteBuffer bb = ByteBuffer.allocateDirect(bmp.getHeight()
*bmp.getWidth()*4);
bb.order(ByteOrder.nativeOrder());
IntBuffer ib = bb.asIntBuffer();
for (int y=0;y<bmp.getHeight();y++) {
for (int x=0;x<bmp.getWidth();x++) {
ib.put(bmp.getPixel(x, y));
}
}
ib.position(0);
bb.position(0);
int[] tmp_tex = new int[1];
gl.glGenTextures(1, tmp_tex, 0);
int tx = tmp_tex[0];
gl.glBindTexture(GL10.GL_TEXTURE_2D, tx);
gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, bmp.getWidth(),
bmp.getHeight(), 0,
GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, bb);
return tx;
}
I call it with simply:
int tex = loadTexture(gl, BitmapFactory.decodeResource
(mContext.getResources(), texture));
where texture is the id for my texture file;
help! thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---