由于类容超长,工具类如下:
三、纹理的工具类:
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();
}
}
}
}
小弟是新手,望高手指点迷津,不甚感激,谢谢!

解决方案 »

  1.   

    这两天我也在学习opengl,看了看你的代码,不知道你解决了这个问题没有,你应该把GLRender中onSurfaceChanged()方法中的
    // 线形滤波
    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]);
    下面
      

  2.   


    哈哈哈哈,我解决了,看这里!!!!!!!!!!!!!!
    http://blog.csdn.net/tabactivity/article/details/18357843
    http://blog.csdn.net/tabactivity/article/details/18357843
    http://blog.csdn.net/tabactivity/article/details/18357843
      

  3.   

    我猜测你是用2.x的手机测试的?可尝试用4.x的手机测试一下,
    2.X的手机对你的纹理图片有一定要求的,如图片尺寸 * 图片尺寸规格定义:
     * 2 4 8 16 32 64 128 256
     * 512 1024 2048 ... 
     * 长宽按以上尺寸随意组合,
     * --如不按以上尺寸组合 在一些android 2.X系统的手机上出现图片映射不到几何物体的框架模型上,
     * 而在android 4.X系统上有所改进,对图片的要求降低了