제목에 따라 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)
를 호출하면, 불행하게도, 내 문제가 해결되지 않는 점에 유의하고자 .
아마도 onResume() 코드를 게시하고 GLSurfaceView 뷰를 초기화하고 설정하는 곳일 수도 있습니다. –
내 게시물에 추가했습니다. – confusedKid
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이 실제로 무엇을하고 있는지 알 수 있습니다. –