[android-developers] Texture appears white in the real device but not in the emulator

19 views
Skip to first unread message

Thiago Assis

unread,
Jul 23, 2009, 1:24:45 AM7/23/09
to Android Developers

Texture appears white in the real device but not in the emulator

Hello fellows,
I’ve already tried to find the solution in other POSTS but none of
the solutions worked.
The problem that I have is that the loaded texture not displayed in
the real device (G1, firmware 1.5). If I turn of the texture and put a
color in the geometry, it works fine.
Details: the file that I’m loading has width and height power of 2.
And I tried with .bmp and .png files, for both I had the same
problem.
My code:
METHOD used to load texture:
private int loadTexture (GL10 gl, Bitmap bmp)
{
int[] tmp_tex= new int[1];
gl.glGenTextures(1, tmp_tex, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, tmp_tex[0]);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_CLAMP_TO_EDGE);
return tmp_tex[0];
}

The FOLLOWING code is inside DRAW method.
>>>>>>>>>>>> DRAW METHOD..
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluOrtho2D(gl, 0.0f,1.2f,0.0f,1.0f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

gl.glDisable(GL10.GL_BLEND);

//texture...
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
bmp=BitmapFactory.decodeResource(c.getResources(), R.drawable.capa);
texBuff=makeFloatBuffer(texture);
gl.glTexCoordPointer(2,GL10.GL_FLOAT,0,texBuff);

tex= loadTexture(gl, bmp);

//small Box...
bb2 =ByteBuffer.allocateDirect(square2.length*4);
bb2.order(ByteOrder.nativeOrder());
squareBuff2 = bb2.asFloatBuffer();
squareBuff2.put(square2);
squareBuff2.position(0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, squareBuff2);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

//back box
bb =ByteBuffer.allocateDirect(square.length*4);
bb.order(ByteOrder.nativeOrder());
squareBuff = bb.asFloatBuffer();
squareBuff.put(square);
squareBuff.position(0);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, squareBuff);
gl.glColor4f(0,0,1,1);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

>>>>>>>>>>>> DRAW METHOD END..
Let me know if you know what is going wrong and what I should do.
My code works fine in the emulator but not in the real device. (This
is a simple code that I’ve done months ago, so I’m using this is a
reference to find the problem.)
Thanks a lot for your attention.
Best regards,

Assis


Thiago Assis

unread,
Jul 23, 2009, 11:09:36 AM7/23/09
to Android Developers

MrChaz

unread,
Jul 23, 2009, 2:52:20 PM7/23/09
to Android Developers

The device requires the textures to be sizes in the power of 2.
e.g. 64x64, 128x128, 256x256 etc
you can have 64x128 etc too

On Jul 23, 6:24 am, Thiago Assis <thiagoassis....@terra.com.br> wrote:
> Texture appears white in the real device but not in the emulator
>
> Hello fellows,
>   I’ve already tried to find the solution in other POSTS but none of
> the solutions worked.
>   The problem that I have is that the loaded texture not displayed in
> the real device (G1, firmware 1.5). If I turn of the texture and put a
> color in the geometry, it works fine.
>   Details: the file that I’m loading has width and height power of 2.
> And I tried with .bmp and .png  files, for both I had the same
> problem.

Thiago Assis

unread,
Jul 23, 2009, 10:03:33 PM7/23/09
to Android Developers

Mr. MrChaz,

As I have already mentioned I'm using texture with sizes power of
2. (I still have the problem.)
Thanks for your contribution.
Regards,

Assis

softak

unread,
Jul 23, 2009, 11:45:23 PM7/23/09
to Android Developers

Are you sure you want to generate texture each time your program draw
screen (several times per second)?
Real phone may have not enough memory for this, comparing with
computer.
And checking generated ID for texture would be helpful. Application
has limited number of such IDs.

Jeff Boody

unread,
Jul 24, 2009, 2:28:34 AM7/24/09
to Android Developers

I also had trouble getting the GLUtils.texImage2D function to work on
real hardware and I suspect they aren't implemented correctly. I would
recommend using the glTexImage2D function directly. You can look at my
Gears4Android demo (http://www.jeffboody.net/gears4android.php) for an
example of how to do this.
--Jeff

MrChaz

unread,
Jul 24, 2009, 5:50:49 AM7/24/09
to Android Developers

Sorry Thiago,
Obviously didn't read the post properly.
Other than the power of 2 thing the other common issue is to do with
the image format
i.e. 16bpp or 32bpp etc
There is a discussion about it all here:
http://groups.google.com/group/android-developers/browse_thread/thread/2cb496c5da3b6955/8342dab8331955dd?q=#8342dab8331955dd

Thiago Assis

unread,
Jul 24, 2009, 9:25:00 PM7/24/09
to Android Developers

Mr. Jeff Boody,

Your solution (avoid using GLUtils.texImage2D) had solved my
problem. Now everything is ok. THANKS!
Thanks again for your contribution.
Thanks!


Assis

Thiago Assis

unread,
Jul 24, 2009, 9:27:09 PM7/24/09
to Android Developers

Mr. Softak,

You are right that we should not do this kind of
initialization in the draw function. I'm doing in this code because is
just a TEST code. In my other codes the initialization is done as
should be.
I solved my problem using the approach of Mr. Jeff Boody,
(Avoid using GLUtils.textImage2D function). Now my texture appears as
should be.
Thanks for your contribution.
Regards,


Assis

Thiago Assis

unread,
Jul 24, 2009, 9:28:27 PM7/24/09
to Android Developers

Mr. MrChaz,

Thanks again for your contribution.
I solved the problem using the approach of Mr. Jeff Boody.
(Not using GLUTils.textImage2D function). Now my code runs as should
be.
Thanks again. Best regards,

Assis

On Jul 24, 4:50 am, MrChaz <mrchazmob...@googlemail.com> wrote:
> Sorry Thiago,
> Obviously didn't read the post properly.
> Other than the power of 2 thing the other common issue is to do with
> the image format
> i.e. 16bpp or 32bpp etc
> There is a discussion about it all here:http://groups.google.com/group/android-developers/browse_thread/threa...
> > > > Assis- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages