由于类容超长,工具类如下:
三、纹理的工具类:
public class TextureUtil {
private int faceNum; // 保存纹理的FloatBuffer
private FloatBuffer[] textureBuffer; // 保存纹理顶点坐标的数组
private float[][] textureVertexArry = {
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f } };
public void setTextureVertexArry(float[][] textureArry) {
this.textureVertexArry = textureArry;
} public void setImagesArry(int[] imagesArry) {
this.imagesArry = imagesArry;
}
public FloatBuffer[] getTextureBuffer() {
return textureBuffer;
} // 贴图数组
private int[] imagesArry = {
R.drawable.view_01,
R.drawable.view_02,
R.drawable.view_03,
R.drawable.view_04,
R.drawable.view_05,
R.drawable.view_06
}; public TextureUtil(int faceNum) {
this.faceNum = faceNum;
this.init();
} public void init() {
textureBuffer = new FloatBuffer[faceNum];
for (int i = 0; i < faceNum; i++) {
textureBuffer[i] = (FloatBuffer) BufferUtil.arrayToBuffer(textureVertexArry[i]);
}
} /**
* 加载和绑定纹理
*
* @param gl
* @param context
* @param index
*/
public int[] loadTexture(GL10 gl, Context context) {
int[] textures = new int[faceNum];
// 创建纹理
gl.glGenTextures(faceNum, textures, 0); for (int i = 0; i < faceNum; i++) {
// 加载位图
Bitmap bitmap = loadBitmap(context, imagesArry[i]); // 设置要使用的纹理
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[i]); // 生成纹理
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); // 回收位图
bitmap.recycle();
}
return textures;
} /**
* 加载位图
*
* @param context
* @param resourceid
* @return
*/
public Bitmap loadBitmap(Context context, int resourceid) {
InputStream is = context.getResources().openRawResource(resourceid);
try {
// BitmapFactory is an Android graphics utility for images
return BitmapFactory.decodeStream(is);
}
finally {
// Always clear and close
try {
is.close();
is = null;
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
小弟是新手,望高手指点迷津,不甚感激,谢谢!
三、纹理的工具类:
public class TextureUtil {
private int faceNum; // 保存纹理的FloatBuffer
private FloatBuffer[] textureBuffer; // 保存纹理顶点坐标的数组
private float[][] textureVertexArry = {
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f },
new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f } };
public void setTextureVertexArry(float[][] textureArry) {
this.textureVertexArry = textureArry;
} public void setImagesArry(int[] imagesArry) {
this.imagesArry = imagesArry;
}
public FloatBuffer[] getTextureBuffer() {
return textureBuffer;
} // 贴图数组
private int[] imagesArry = {
R.drawable.view_01,
R.drawable.view_02,
R.drawable.view_03,
R.drawable.view_04,
R.drawable.view_05,
R.drawable.view_06
}; public TextureUtil(int faceNum) {
this.faceNum = faceNum;
this.init();
} public void init() {
textureBuffer = new FloatBuffer[faceNum];
for (int i = 0; i < faceNum; i++) {
textureBuffer[i] = (FloatBuffer) BufferUtil.arrayToBuffer(textureVertexArry[i]);
}
} /**
* 加载和绑定纹理
*
* @param gl
* @param context
* @param index
*/
public int[] loadTexture(GL10 gl, Context context) {
int[] textures = new int[faceNum];
// 创建纹理
gl.glGenTextures(faceNum, textures, 0); for (int i = 0; i < faceNum; i++) {
// 加载位图
Bitmap bitmap = loadBitmap(context, imagesArry[i]); // 设置要使用的纹理
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[i]); // 生成纹理
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); // 回收位图
bitmap.recycle();
}
return textures;
} /**
* 加载位图
*
* @param context
* @param resourceid
* @return
*/
public Bitmap loadBitmap(Context context, int resourceid) {
InputStream is = context.getResources().openRawResource(resourceid);
try {
// BitmapFactory is an Android graphics utility for images
return BitmapFactory.decodeStream(is);
}
finally {
// Always clear and close
try {
is.close();
is = null;
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}
小弟是新手,望高手指点迷津,不甚感激,谢谢!
解决方案 »
- google map Javascipt api on andoird,有没有能运行的例子。
- android service获取按键
- 手机连上电脑了但是file explorer视图中不显示手机的sdcard内容。
- android 2.2 Min SDK Version是多少?
- 写了一个自定义view,不知道除了什么问题
- 简单问题,请问为什么webview里面的js调用小米1可以用小米3用不了?!
- Android:Andup-CD[Trj]是什么病毒?为什么APK会被Avast会报这个病毒?
- 安卓程序,访问网络时路径正确,但是却得不到资源
- android @ 别人 怎么写
- Android使用新浪登录的问题
- android 摄像头hal移植
- 大家帮忙投票,谢谢
// 线形滤波
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
放在TextureUtil类中loadTexture()方法
// 设置要使用的纹理
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[i]);
下面
哈哈哈哈,我解决了,看这里!!!!!!!!!!!!!!
http://blog.csdn.net/tabactivity/article/details/18357843
http://blog.csdn.net/tabactivity/article/details/18357843
http://blog.csdn.net/tabactivity/article/details/18357843
2.X的手机对你的纹理图片有一定要求的,如图片尺寸 * 图片尺寸规格定义:
* 2 4 8 16 32 64 128 256
* 512 1024 2048 ...
* 长宽按以上尺寸随意组合,
* --如不按以上尺寸组合 在一些android 2.X系统的手机上出现图片映射不到几何物体的框架模型上,
* 而在android 4.X系统上有所改进,对图片的要求降低了