2011-07-08 119 views
0

我已经制作了一个游戏,其中所有对象都使用一个精灵表,目前效果很好。现在我已经制作了一个拥有自己纹理的物体,但是(至少在我的手机上是一个Evo)它只是显示了一架白色飞机。但是,这在模拟器上正常工作。这是我装的纹理代码:试图加载两个纹理,但只有一个被加载

public void LoadTexture(GL10 gl, Context context) throws IOException { 
    InputStream is = context.getAssets().open("Image.png"); 
    Bitmap bitmap = null; 
    try{ 
     bitmap = BitmapFactory.decodeStream(is); 
    }finally{ 
     try{ 
      is.close(); 
      is = null; 
      gl.glGenTextures(1, texture,0); 
      gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); 

      //Create Nearest Filtered Texture 

      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST); 
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 

      //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE 
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); 
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); 

      //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap 
      GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 


      gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
      //Clean up 


      bitmap.recycle(); 
     }catch(IOException e){ 

     } 
    } 

} 

而且,在不同的类:

public void LoadTexture(GL10 gl, Context context) throws IOException{ 
    InputStream is = context.getAssets().open("end.png"); 
    Bitmap bitmap = null; 
    try{ 
     bitmap = BitmapFactory.decodeStream(is); 
    }finally{ 
     try{ 
      is.close(); 
      is = null; 
      gl.glGenTextures(1, texture,0); 
      gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); 

      //Create Nearest Filtered Texture 

      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST); 
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 

      //Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE 
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT); 
      gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT); 

      //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap 
      GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 


      gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
      //Clean up 


      bitmap.recycle(); 
     }catch(IOException e){ 

     } 
    } 
} 

两个类都有一个平局框架例程,启用/禁用的质感,和一个私有成员(int[] texture = new int[1]) 。我尝试改变这个变量,但是无论如何也会发生同样的事情。两个纹理都加载到onSurfaceCreated(GL10 gl,EGLConfig config);

回答

0

我正面临类似的问题,但可能并非如此。我试图加载的图像也是我的应用程序的图标,不知何故,它没有加载它我改变了我的图像,这是没有参考的操作系统,它工作正常

相关问题