2011-02-09 12 views
1

自分のアプリケーションが自分のエミュレータで正しく見える問題が発生していますが、携帯電話では自分のシーンの断片だけが表示されます。Androidエミュレータと電話OpenGLの不一致

画像here(エミュレータが右の一つです。

マイレンダラーコードをここで見ている。(このクラスは抽象的であるが、すべての実装クラスがやっているが、ポリゴンを描画している)

public abstract class AbstractRenderer implements Renderer { 
float x = 0.5f; 
float y = 1f; 
float z = 3; 

boolean displayCoordinateSystem = true; 

public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) { 
    gl.glDisable(GL10.GL_DITHER); 
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST); 
    gl.glClearColor(.5f, .5f, .5f, 1); 
    gl.glShadeModel(GL10.GL_SMOOTH); 
    gl.glEnable(GL10.GL_DEPTH_TEST); 
} 

public void onSurfaceChanged(GL10 gl, int w, int h) { 
    gl.glViewport(0, 0, w, h); 
    float ratio = (float) w/h; 
    gl.glMatrixMode(GL10.GL_PROJECTION); 
    gl.glLoadIdentity(); 
    gl.glFrustumf(-ratio, ratio, -1, 1, 0, 10); 
} 

public void onDrawFrame(GL10 gl) { 
    gl.glDisable(GL10.GL_DITHER); 
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); 
    gl.glMatrixMode(GL10.GL_MODELVIEW); 
    gl.glLoadIdentity(); 
    GLU.gluLookAt(gl, x, y, z, 0f, 0, 0f, 0f, 1f, 0f); 
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 

    if(displayCoordinateSystem) { 
     drawCoordinateSystem(gl); 
    } 

    draw(gl); 

//  gl.glFlush(); 
} 

private void drawCoordinateSystem(GL10 gl) { 
    ByteBuffer vbb = ByteBuffer.allocateDirect(6*3*4); 
    vbb.order(ByteOrder.nativeOrder()); 
    FloatBuffer vertices = vbb.asFloatBuffer(); 

    ByteBuffer ibb = ByteBuffer.allocateDirect(6*2); 
    ibb.order(ByteOrder.nativeOrder()); 
    ShortBuffer indexes = ibb.asShortBuffer(); 

    final float coordLength = 27f; 

    //add point (-1, 0, 0) 
    vertices.put(-coordLength); 
    vertices.put(0); 
    vertices.put(0); 

    //add point (1, 0, 0) 
    vertices.put(coordLength); 
    vertices.put(0); 
    vertices.put(0); 

    //add point (0, -1, 0) 
    vertices.put(0); 
    vertices.put(-coordLength); 
    vertices.put(0); 

    //add point (0, 1, 0) 
    vertices.put(0); 
    vertices.put(coordLength); 
    vertices.put(0); 

    //add point (0, 0, -1) 
    vertices.put(0); 
    vertices.put(0); 
    vertices.put(-coordLength); 

    //add point (0, 0, 1) 
    vertices.put(0); 
    vertices.put(0); 
    vertices.put(coordLength); 

    for(int i = 0; i < 6; i++) { 
     indexes.put((short)i); 
    } 

    vertices.position(0); 
    indexes.position(0); 

    gl.glColor4f(1, 1, 0, 0.5f); 
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices); 
    gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes); 

    indexes.position(2); 
    gl.glColor4f(0, 1, 0, 0.5f); 
    gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes); 

    indexes.position(4); 
    gl.glColor4f(0, 0, 1, 0.5f); 
    gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes); 
} 

protected abstract void draw(GL10 gl); 
} 

私は、エミュレータの実装によってデフォルトで設定されている値を設定していないと思いますが、そのことについては何の手掛かりもありません。

あなたから聞いて欲しいと思っています!

答えて

1

これは、デプスバッファの問題があります:glFrustumのmanページで「ノート」セクションから:

近くに設定してはいけません0

にあなたがに近い値を計算する必要があります可能な限りカメラから離れていて、できるだけ近くにいて、描画したいものを取り囲んでいます。

+1

また、あなたの頂点がカメラから27単位離れていて、遠方距離が10単位しかないように見えます。良い出発点はgl.glFrustumf(....、0.1f、100.0f)です。 ryanmが提案したように値を調整することができます。 – Gilead

+0

あなたは絶対に正しいです! – CoolMcGrrr

+0

@Gilead私は全長atmで表示されていない頂点に心配していません(彼らはとにかくアプリをリリースする前に外出しています)。しかし、あなたは、欲求不満のための正しい値を微調整する便利な方法を提供しました。 Thxあなたの入力のためにたくさん! – CoolMcGrrr

関連する問題