2011-11-18 7 views
4

제목에 따라 GLSurfaceView는 일시 중지 상태에서 다시 시작한 후 비어 있습니다. 렌더러의 onSurfaceCreated, onSurfaceChanged 및 이 다시 시작된 후에 호출되지만 화면은 여전히 ​​비어 있습니다.Android : 앱 재개 후 GLSurfaceView가 검은 색입니다.

다음은 관련 코드입니다 :

@Override 
public void onSurfaceCreated(GL10 gl, EGLConfig config) { 
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
    gl.glShadeModel(GL10.GL_SMOOTH); 
    gl.glClearDepthf(1.0f); 
    gl.glEnable(GL10.GL_DEPTH_TEST); 
    gl.glDepthFunc(GL10.GL_LEQUAL); 

    boxWidth = 0.5f; 
    boxHeight = 0.5f; 
    boxCenter = new float[] { 0.5f, 0.5f }; 

    Log.v("resume", "onSurfaceCreated"); 
} 

@Override 
public void onSurfaceChanged(GL10 gl, int width, int height) {  
    gl.glViewport(0, 0, width, height); 
    gl.glMatrixMode(GL10.GL_PROJECTION); 
    gl.glLoadIdentity(); 
    gl.glOrthof(0, 1, 0, 1, -5, 5); 
    gl.glMatrixMode(GL10.GL_MODELVIEW); 

    viewHeight = height; 
    viewWidth = width; 

    Log.v("resume", "onSurfaceChanged"); 
} 

@Override 
public void onDrawFrame(GL10 gl) { 
    gl.glLoadIdentity(); 

    float halfW = boxWidth/2.0f; 
    float halfH = boxHeight/2.0f; 

    float left = Math.max(boxCenter[0]-halfW, 0.001f); 
    float right = Math.min(boxCenter[0]+halfW, 0.999f); 
    float top = Math.min(boxCenter[1]+halfH, 0.999f); 
    float bottom = Math.max(boxCenter[1]-halfH, 0.001f); 

    boxHeight = Math.max(top - bottom, 0.05f); 
    boxWidth = Math.max(right - left, 0.05f); 
    boxCenter[0] = left + boxWidth/2.0f; 
    boxCenter[1] = bottom + boxHeight/2.0f; 

    float vertices[] = { 
      left, top, 0.0f, 
      left, bottom, 0.0f, 
      right, bottom, 0.0f, 
      right, top, 0.0f 
    }; 

    ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4); 
    byteBuf.order(ByteOrder.nativeOrder()); 
    vertexBuffer = byteBuf.asFloatBuffer(); 
    vertexBuffer.put(vertices); 

    gl.glTranslatef(0.001f, -0.001f, -3.0f); 

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | 
      GL10.GL_DEPTH_BUFFER_BIT); 

    vertexBuffer.position(0); 

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); 
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, 
      vertexBuffer); 

    gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); 

    gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, 4); 
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); 

    Log.v("resume", "drawing"); 
} 

난 당신이 onSurfaceChanged 내부 GL 컨텍스트를 다시 작성해야 읽었습니다,하지만 난 onSurfaceCreated를 호출 할 때 이미 어떻게했는지, 또는 경우에 확실하지 않다.

도와주세요!

편집 : '(여기 GLSurface라고 함)

public void onResume() { 
    super.onResume(); 
    if (mGLSurface != null) { 
    if (mRenderer != null) { 
     float[] center = new float[2]; 
     center[0] = settings.getFloat("renderer_boxCenter0", 0.5f); 
     center[1] = settings.getFloat("renderer_boxCenter1", 0.5f); 
     mRenderer.setBoxCenter(center); 
     mRenderer.setBoxWidth(settings.getFloat("renderer_boxWidth", 0.5f)); 
     mRenderer.setBoxHeight(settings.getFloat("renderer_boxHeight", 0.5f)); 
    } 
    mGLSurface.onResume(); 
} 

내가 GLSurfaceView의 onResume에서 많은 일을하지 않았고, I didn 히 : 여기 는 GLSurfaceView를 포함하는 활동에서 onResume 코드는 내 EGL 컨텍스트를 다시 얻으려면 특별히해야 할 일을 제안하는 문서를 찾으십시오.

편집 2 : 나는 또한 내 GLSurfaceView의 생성자에서 setPreserveEGLContextOnPause(true)를 호출하면, 불행하게도, 내 문제가 해결되지 않는 점에 유의하고자 .

+0

아마도 onResume() 코드를 게시하고 GLSurfaceView 뷰를 초기화하고 설정하는 곳일 수도 있습니다. –

+0

내 게시물에 추가했습니다. – confusedKid

+0

onSurfaceCreated의 끝에서'gl.glOrthof (0, 1, 0, 1, -5, 5); '를 설정하고 앱을 처음 실행할 때 아무 것도 나타나지 않는지보십시오. 차이가 없다면 onDraw에서'gl.glClearColor (1.0f, 0.0f, 0.0f, 0.0f); '(배경색을 빨간색으로 설정)을 설정 한 다음 gl.glClearColor (0.0f , 0.0f, 1.0f, 0.0f); onResume()이 호출 된 후'(즉 파란색). 그렇게하면 OpenGL이 실제로 무엇을하고 있는지 알 수 있습니다. –

답변

0

다소 길지만 오리엔테이션이나 설정 변경을 제어하려고합니까 (예 : public void onConfigurationChanged(Configuration config)에 내 작업이 오버라이드되어 있습니까)?

은 내가 onConfigurationChanges()이있는 경우 내 매니페스트 파일 내 활동과 android:screenOrientation="landscape"에서 오버라이드 (override) 발견하지만 android:configChanges="orientation" 난 당신이 는 안드로이드 3.X와 장치에서 지원됩니다 (참)

+0

안녕하세요, 내 응용 프로그램을 가로 방향으로 만로드하도록 강요했습니다. onConfigurationChanges()를 실제로 재정의하지 않았습니다. 나는 단지 내 manifest 파일에'android : screenOrientation = "landscape"'를 넣는다. – confusedKid

+0

onConfigurationChanges에서 super를 호출하고 실제로 아무것도 수행하지 않더라도 manifest 파일에'onConfigurationChanges()'를 재정의하고 해당하는'configChanges = "orientation"을 추가하여 수정하는지 확인하십시오. 그것은 적어도 내 자신의 애플 리케이션을위한 문제를 해결했다. 단점은 더 느린 장치에서는 가로로 올바르게 전환하기 전에 다시 시작한 후 몇 초 동안 앱이 엉망인 세로보기로 표시된다는 성가신 부작용이 발생한다는 것입니다. –

+0

'onConfigurationChanged()'를 의미 했습니까? 나는 당신이 제안한 것처럼 그것을 무시하고'configChanges'를 추가하려고했지만, 문제는 계속됩니다. – confusedKid

3

setPreserveEGLContextOnPause을 설명 어떤 식으로 뭔가를 얻을 그리고 위로. 에서) 활동 및 GlSurfaceView.onResume (의 onPause 방법에)

당신이 GlSurfaceView.onPause (호출 GlSurfaceView의 부모 활동의 당신이 찾고있는 솔루션입니다 (심지어 다음은 지원되는지 여부를 특정 장치입니다) 액티비티의 onResume 메소드.

이렇게하면 모든 텍스처와 버퍼가 손실됩니다. 이 시점에서 다시로드해야합니다.

+0

당신은 내 생명을 구했어 ... – Dhrupal

관련 문제