我在OpenGL-ES上做了我的第一步。 Atm我可以在方形多边形上加载二次幂(POT)纹理,我可以在屏幕上旋转和缩放。如果我尝试加载非POT png,则纹理显示为白色。
我需要做一些技巧来将非POT纹理转换为POT位图以填充方形多边形的纹理。如何将它们转换为POT位图?
这是我必须加载纹理的实际代码:
来自资产DIR:
String imagePath = "radiocd5.png";
AssetManager mngr = context.getAssets();
// Create an input stream to read from the asset folder
InputStream is=null;
try {
is = mngr.open(imagePath);
} catch (IOException e1) { e1.printStackTrace(); }
//Get the texture from the Android resource directory
InputStream is = context.getResources().openRawResource(R.drawable.radiocd5);
Bitmap bitmap = BitmapFactory.decodeStream(is);
//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
FROM RES / DRAWABLE:
//Get the texture from the Android resource directory
InputStream is = context.getResources().openRawResource(R.drawable.radiocd5);
Bitmap bitmap = BitmapFactory.decodeStream(is);
//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
答案 0 :(得分:0)
最好的方法是重新采样图像,将其大小调整为2的幂(POT)。 Google'图片重新采样'并准备面对一些沉重的数学;)Lanzcos重新取样http://en.wikipedia.org/wiki/Lanczos_resampling是你可能考虑的几种方式之一。双线性插值也很好。