2012-11-27 57 views
1

我運行的應用程序顯示許多位圖和一個翻譯動畫。在仿真器上,這種方式始終都能正常工作,除了切換寬度和高度(從設備派生)之外的罕見例外。然而,在朋友的Galaxy SIII上,沒有任何紋理顯示,四邊形也沒有。嘗試查看動畫是否運行後,它沒有,但glClear函數爲背景繪製了正確的顏色。因此該程序仍在渲染。我正在使用以下渲染器的正交視圖。Android應用程序在模擬器上顯示,但不在電話上

import javax.microedition.khronos.egl.EGLConfig; 
import javax.microedition.khronos.opengles.GL10; 
import android.content.Context; 
import android.opengl.GLSurfaceView.Renderer; 


public class GLrenderer implements Renderer { 

private Context context; 
long startTime; 
public GLrenderer(Context context) { 
    this.context = context; 

} 
public void onSurfaceCreated(GL10 gl, EGLConfig config) {  
    //Load the texture for the cube once during Surface creation 

    MenuGameLoop.button.now.position_x=0; 
    MenuGameLoop.button.past.position_x=0; 
    MenuGameLoop.button.loadGLTexture(gl, this.context); 
    MenuGameLoop.overlay.loadGLTexture(gl, this.context); 
    for(int i=0;i<Splash.cubes.size();i++){ 
    Block ice=Splash.cubes.get(i); 
    ice.loadGLTexture(gl, this.context, ice.width, ice.height,ice.overall,ice.subWidth, ice.subHeight); 
    } 
    gl.glEnable(GL10.GL_BLEND); 
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); 
    gl.glEnable(GL10.GL_TEXTURE_2D);    
    gl.glShadeModel(GL10.GL_SMOOTH);    
    gl.glClearColor(0.0f, 0.666f, 0.831f, 1f); 
    gl.glClearDepthf(1.0f);      
    gl.glEnable(GL10.GL_DEPTH_TEST);   
    gl.glDepthFunc(GL10.GL_LEQUAL);    

    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST); 
} 


public void onDrawFrame(GL10 gl) { 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);  
    gl.glLoadIdentity(); 
    MenuGameLoop.overlay.draw(gl);  
    gl.glPushMatrix(); 
    gl.glTranslatef((float)MenuGameLoop.button.mid.position_x,(float)MenuGameLoop.button.mid.position_y+(Splash.sizeY/2), 0); 
    MenuGameLoop.button.draw(gl); 

    gl.glPopMatrix(); 
    for(int i=0;i<Splash.cubes.size();i++){ 
     gl.glPushMatrix(); 
     Block ice=Splash.cubes.get(i); 
     gl.glTranslatef (ice.posX,ice.posY, 0); 
     ice.draw(gl); 
     gl.glPopMatrix(); 
     } 

} 

public void onSurfaceChanged(GL10 gl, int width, int height) { 

    if(height == 0) {     
     height = 1;       
    } 

    gl.glViewport(0, 0, width, height);  
    gl.glMatrixMode(GL10.GL_PROJECTION);  
    gl.glLoadIdentity();      

    gl.glOrthof(0f, (float)width, (float)height, 0f, 0.1f, 100.0f); 

    gl.glMatrixMode(GL10.GL_MODELVIEW);  
    gl.glLoadIdentity();      
    } 
} 

如果無法從上面推論出問題,有沒有什麼特別的事情我應該避免/添加到其他代碼段?

回答

0

請確保您使用的是兩次冪的紋理。另外,你可能會選擇不兼容的OpenGL ES配置,它可以在仿真器上工作,但不能在設備上工作。

+0

動畫紋理是兩個紋理的力量。但是,另外兩個是程序位圖,所以我沒有將它們創建爲兩個冪。如果是這種情況,那麼動畫紋理和四邊形仍然不會顯示?對於OpenGL ES配置的情況,你是什麼意思?我是否必須將EGL合併到我的程序中? – Behemyth

+0

關於OpenGL ES配置 - 是的,你應該看看'setEGLConfigChooser()'方法 – keaukraine

+0

非常感謝! – Behemyth

相關問題