2014-03-02 62 views
0

我嘗試在我的Android應用程序中顯示一個立方體,但我似乎並沒有在我的HTC One SV上正常工作,因爲屏幕只保留白色我想是因爲glClearColor()) 這裏有兩個相關類的代碼:Android - OpenGL不能在真實手機上工作,但在仿真器上一切正常

public class ClassicByteRenderer implements GLSurfaceView.Renderer { 

private Square square = new Square(); 
public int width = 0; 
public int height = 0; 

public void onDrawFrame(GL10 gl) { 
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); 
    gl.glMatrixMode(GLES10.GL_PROJECTION); 
    gl.glLoadIdentity(); 
    GLU.gluPerspective(gl, 45.0F, (float) this.width/(float) this.height,0.1F,100.0F); 
    GLU.gluLookAt(gl, 5.0F, 10.0F, 5.0F, 1.0F, 1.0F, 0.0F, 0.0F, 1.0F, 0.0F); 
    gl.glMatrixMode(GLES10.GL_MODELVIEW); 
    gl.glLoadIdentity(); 
    this.drawCube(gl); 
} 

public void drawCube(GL10 gl) { 
    gl.glColor4f(1.0F,1.0F,0.0F,1.0F); 
    this.square.draw(gl); 

    gl.glTranslatef(0.0F,0.0F,-2.0F); 
    gl.glColor4f(1.0F,0.0F,0.0F,1.0F); 
    this.square.draw(gl); 

    gl.glTranslatef(1.0F,0.0F,1.0F); 
    gl.glRotatef(90.0F,0.0F,1.0F,0.0F); 
    gl.glColor4f(0.0F,0.0F,1.0F,1.0F); 
    this.square.draw(gl); 

    gl.glTranslatef(0.0F,0.0F,-2.0F); 
    gl.glColor4f(0.0F,1.0F,0.0F,1.0F); 
    this.square.draw(gl); 

    gl.glTranslatef(0.0F,-1.0F,1.0F); 
    gl.glRotatef(90.0F,-1.0F,0.0F,0.0F); 
    gl.glColor4f(0.0F,1.0F,1.0F,1.0F); 
    this.square.draw(gl); 

    gl.glTranslatef(0.0F,0.0F,2.0F); 
    gl.glColor4f(1.0F,0.0F,1.0F,1.0F); 
    this.square.draw(gl); 
} 

public void onSurfaceChanged(GL10 gl, int width, int height) { 
    GLES20.glViewport(0, 0, width, height); 
    this.width = width; 
    this.height = height; 
} 

public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
    GLES20.glClearColor(1.0F, 1.0F, 1.0F, 1.0F); 
    GLES20.glEnable(GLES20.GL_DEPTH_TEST); 
    GLES20.glEnable(GLES20.GL_TEXTURE_2D); 
    GLES20.glDisable(GLES20.GL_CULL_FACE); 
    GLES20.glDepthFunc(GLES20.GL_LEQUAL); 
    gl.glHint(GLES10.GL_PERSPECTIVE_CORRECTION_HINT, GLES10.GL_NICEST); 
    GLES20.glDepthMask(true); 
} 

} 

這裏另外一個可能是必要的:

public class ClassicByteView extends GLSurfaceView { 

public ClassicByteView(Context context) { 
    super(context); 
    super.setEGLConfigChooser(true); 
    this.setEGLContextClientVersion(2); 
    this.setRenderer(new ClassicByteRenderer()); 
    this.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY); 
} 
} 

如何一切都應該看起來像(這是怎麼回事在模擬器中呈現):

回答

0

我自己能夠解決問題。解決方案是在ClassicByteView類中刪除

super.setEGLConfigChooser(true); 
this.setEGLContextClientVersion(2); 

。現在一切正常。

相關問題