2011-02-09 4 views
1

내 응용 프로그램이 내 에뮬레이터에서 제대로 보이는 문제가 있습니다. 그러나 휴대 전화에서는 내 장면 조각 만 표시합니다.Android 에뮬레이터 대 전화 opengl inconsistensies

이미지 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의 사람 페이지에서 '메모'섹션에서 :

근처 설정해서는 안됩니다 0

에 당신은에 가까운 값을 계산한다 가능한 한 카메라에서 멀어지고, 가능한 한 가까 이서, 그리려는 것들을 여전히 포함합니다.

+1

또한 정점이 카메라에서 27 단위 떨어져 있고 원거리가 단지 10 단위 인 것처럼 보입니다. 좋은 출발점은 gl.glFrustumf (...., 0.1f, 100.0f)입니다. ryanm이 제안한대로 값을 조정할 수 있습니다. – Gilead

+0

당신은 절대적으로 옳습니다! – CoolMcGrrr

+0

@Gilead 나는 전 길이 atm에서 보여주지 않는 꼭지점에 대해서는별로 관심이 없다. (그들은 어쨌든 앱을 공개하기 전에 외출 중이다.) 그러나 절두의 올바른 값을 조정하는 유용한 방법을 제공했습니다. Thx 귀하의 의견을 많이! – CoolMcGrrr