Skip to content Skip to sidebar Skip to footer

Trying To Draw Textured Triangles On Device Fails, But The Emulator Works. Why?

I have a series of OpenGL-ES calls that properly render a triangle and texture it with alpha blending on the emulator (2.0.1). When I fire up the same code on an actual device (Dro

Solution 1:

I had exactly this issue when I moved from SDK 3 to 4. My textures would display on the emulator but not on the real device (Motorola Milestone/Droid).

All your textures must be binary powers of two. Mine were 256x256. However the reason the textures don't display is that the OS is scaling them from their binary power sizes to display on the Milestone's high density screen.

The solution is easy - just move the textures to the drawable-nodpi directory and the OS won't scale them when it loads them.

Solution 2:

Im also new to Android OpenGL ES dev. I own a Milestone (euro version for Droid).

From what i can see so far, firing several tutorial apps from different books/websites on my milestone, it seems this phone handle OpenGL ES in a different way than all other android phones released so far.

I think its related to the OpenGL extensions supported on the device.

check this link for the list of the supported extensions, im pretty sure a code guru will find why exactly the droid is handling opengl es in such a weird way.

http://www.rbgrn.net/content/345-hands-on-motorola-droid-opengl-es-specs

Hope this helps.. a bit


EDITED :

I tweaked the manifest.xml and noticed when using

<uses-sdkandroid:minSdkVersion="6"/>

the resources aren't loading at all.

When using

<uses-sdkandroid:minSdkVersion="3"/>

resources are loading fine.

So i switched back to

<uses-sdkandroid:minSdkVersion="6"/>

and changed the way the bitmap is loaded.

Try to replace :

//Get the texture from the Android resource directory Bitmapbitmap= BitmapFactory.decodeResource(context.getResources(), reasource_id, sBitmapOptions); 

with :

InputStream is = context.getResources().openRawResource(your.resource.there);
    Bitmap bitmap = null;
    try {
        bitmap = BitmapFactory.decodeStream(is);

    } finally {
        //Always clear and closetry {
            is.close();
            is = null;
        } catch (IOException e) {
        }
    }

Textures are loading fine on my milestone with that code, hope this work for yours !

Solution 3:

Make sure you load your bitmaps with a appropriate BitmapConfig that is not scaling your image behind the scenes, because this happens.

Also, is there a reason you are storing your pngs in /raw/ instead of /drawable/?

Solution 4:

Dullahx's edited answer solved my problem on the same issue. thanks a lot, it was bugging me the last two days!

I was trying to map a texture on samsung galaxy tab, which was displayed successfully on the emulator but only the plane was displayed on the device.

I replaced my code:

plane.loadBitmap(BitmapFactory.decodeResource(getResources(),R.drawable.jay));

with this one:

InputStream is = context.getResources().openRawResource(R.drawable.jay);

// Load the texture.
plane.loadBitmap(BitmapFactory.decodeStream(is));

and it worked on the device too!

But be careful about the minSdkVersion if you are also trying to map a texture on a fullscreen size rectangle like me. If I use

<uses-sdkandroid:minSdkVersion="3"/>

on samsung galaxy tab, my plane was not rendered fullscreen. It was rendered according to the fullscreen size of a device using sdk version 3. I changed this to

<uses-sdkandroid:minSdkVersion="8"/>

and my fullscreen rectangle is back with its texture on.

Hope this helps, too.

Solution 5:

I am unsure of what your problem is, I'm pretty new to development in general, but my OpenGL android problems with difference between the emulator and the phone were:

-Emulator can support non 2^x dimensions for bitmaps, phone cannot -Emulator flipped screen in NDK for openGL so I had to use negative coordinates to define the view in the emulator, while my G1 used the coordinates non-negated.

Hopefully this is able to help you in someway.

Post a Comment for "Trying To Draw Textured Triangles On Device Fails, But The Emulator Works. Why?"