由于类容超长,工具类如下:
三、纹理的工具类:
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();
}
}
}
}
小弟是新手,望高手指点迷津,不甚感激,谢谢!
解决方案 »
- Android 开发 视频显示的问题
- android下使用Cursor如何获取专辑图片?
- libcurl编译
- 日历 进入日历新建一个日程后再删除,总览界面还有绿色的图标显示,应该清除
- 求解,android读取AndroidManifest中meta-data值为长数字问题
- 关于android:ellipzise
- 低版本的sdk中调用VERSION_CODES.JELLY_BEAN 为啥不报错?
- 请问安装Android stdio 怎么换模拟器?
- 已知framework.apk里有语言资源,但设置里不显示
- android studioyn模拟器只可以选择一个,别的怎么下载?
- 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系统上有所改进,对图片的要求降低了