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);