0
votes

I am very new to OpenGL ES. To my understanding openGL ES only allows power of two sized images for textures (eg 512*512 or 256*256 etc...). I am looking for a way to display images of different sizes as textures but they are not power of 2 sized and their size varies.

The pictures will be downloaded from the internet. Resizing them before downloading is out of the question.

Is there a way to use non POT sized images for textures? Do I have to create a method to resize them? Is there a library out there somewhere that does that?

The textures will be applied to rectangles using the library min3d: http://code.google.com/p/min3d/ thks!

EDIT:

example of texture loading from resources:

InputStream is =getResources().openRawResource(R.drawble.drawable1);

Bitmap bitmap;

bitmap = BitmapFactory.decodeStream(is);
1
OpenGL ES 2.0 does not have such restriction for texture sizes. If just possible switch to it instead.harism

1 Answers

1
votes

When you load in an image, you could create a larger Bitmap container for it that is of a POT size. Then copy the non-POT image into it. When you load the new Bitmap as a texture you can then crop it to the size you want (third parameter of glTexParameteriv()).

To create the container Bitmap:

// work out the pot size you need from the source Bitmap's size
// ...

Bitmap bigger = Bitmap.createBitmap(potWidth, potHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bigger);
canvas.drawBitmap(nonPOTBmp, 0, 0, null);

// free up memory
nonPOTBmp.recycle();