Mipmap Generation

by Mike » Wed, 15 Jul 2009 00:26:53 GMT

Sponsored Links
 I've created a simple heightmap renderer for Android, and am at the
point where I'd like to apply textures to the terrain. I've had
success with applying a simple texture but there is an unbearable
amount of texture aliasing visible, I guess because there are no
mipmaps for the texture. I could not find any way of automatically
generating mipmaps as all the usual OpenGL methods seem to be

Have any of you figured out how to generate mipmaps on Android? Do we
need to write our own implementation to to it?



Mipmap Generation

by Mike » Wed, 15 Jul 2009 04:08:55 GMT

 Well I've come up with a solution, but I'd still like to hear from
others if you have a better way of doing it.

private int loadTexture(GL10 gl, Bitmap bmp)
        int level = 0;
        int size = bmp.getHeight();

        int[] textures = new int[1];
        gl.glGenTextures(1, textures, 0);
        int textureId = textures[0];

        gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

        while(size >= 1)
                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0);

                if(size == 1)

                size /= 2;
                Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, size, size, true);
                bmp = bmp2;

        return textureId;


Sponsored Links

Mipmap Generation

by Nightwolf » Sat, 25 Jul 2009 00:30:56 GMT

 In texture loading function please try the following

gl.glGenTextures(1, texID, 0);

gl.glBindTexture(GL10.GL_TEXTURE_2D, texID[0]);


Mipmap Generation

by nea » Fri, 31 Jul 2009 03:05:45 GMT


I am also currently trying to get MipMaps to work and eventually this
is the thread that pops up several times in the search ^^'.

The problem I have with your posted solution, it does not work for me.
As soon as I try it your way I do not get any texture at all. It just
stays white. What could be the problem, as it should be the normal way
to to MipMaps by adding the new images to the according level. But as
soon as I add a second level it stays white. I define
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

before, but still it won't work.

Does anybody has a solution or a hint what could help here?

Thanks in advance.



Mipmap Generation

by Ante » Sat, 05 Sep 2009 00:49:51 GMT

 Hi Mike.

This works in the emulator:
if(gl instanceof GL11)
    gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP,
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

Though, this doesnt help if your device doesnt support the GL11

I tried your mip mapping function but without success. You wouldnt
happen to have a working example?

Best regards,


Other Threads

1. Android Reviews

Google Android Phone Reviews and Rumoursa  rel="nofollow" href="http://www.android-">http://www.android-


2. scalable vector graphics scalable vector graphics scalable vector graphics

Vector graphics are not magical. First of all, a vector graphics
engine require expensive rendering if you want to be able to create
results that have as much details and effects as traditional raster
graphics. They also cause no end of trouble when you try to render
them at small sizes. You could create a beautiful icon in SVG, that
looks amazing at 256x256, but will look really bad at 32x32. In this
case, you'd be better off mixing vectors (for large sizes) and

The contrary is also true. There are many effects that OpenGL doesn't
let you do easily. For instance, many things you can do today with
Android's 2D APIs cannot be done easily in OpenGL ES 1.0 and 1.1.
Circular gradients are a very good example. OpenGL ES 2.0 lets you do
a lot more but the chips are very new and it will take some time
before they are ubiquitous. Also you cannot count on all phones to
have hardware support for accelerating graphics nor can you count on
all phones having good graphics drivers.

Actually you have to. Because you don't have control over the
rendering, scaling vectors can produce results that are wrong by a few
pixels at certain sizes. You cannot guarantee the result.

Android provides a 2D raster API, which you need anyway to render
vector graphics. It is perfectly possible to add an API on top of the
current one. Note that Android already provides some support for pixel
independence and vector graphics. All Views can be sized using logical
units (dip, for device independent pixel, and sp, for scaled point)
and you can define vector graphics in XML. For instance, Android's
circular progress bar is defined entirely this way:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:drawable="@android:drawable/progress_circular_background" />
       <shape android:shape="ring"
                  android:endColor="#ffffffff" />

Again, vector graphics won't do anything magical for you. The current
approach, using 9-patches (stretchable bitmaps) and logical units, is
a good match for current and soon-to-come hardware: it's flexible and

Note that the next public Android SDK will provide a way to enable
hardware acceleration (through OpenGL) for the standard Views and 2D
APIs. But again, this won't do any good on devices with no good
hardware support and good drivers. Hardware acceleration has also
other drawbacks compared to a software rendering (for instance, you
cannot easily redraw just a small portion of the screen, you have to
refresh everything.)

Romain Guy


3. scalable vector graphics scalable vector graphics scalable vector graphics

4. (D)GPS good to 10 cm

5. How to detect item selected in Spinner View as selecting different items

6. AutoCompleteTextView - does not display content

7. How to make screen scroll horizontally