OpenGL ES 上下文在解锁时被压缩 - 横向到纵向

OpenGL ES context squashed on unlock - landscape to portrait

在开发仅在纵向模式下运行的游戏时,我尝试通过清单强制使用 sensorPortrait:

    android:configChanges="locale|orientation|keyboardHidden|screenSize|screenLayout"
    android:screenOrientation="sensorPortrait"

但是当我将设备锁定为纵向模式时,将其旋转为横向模式然后解锁时,会发生这种情况:

这是纵向的样子:

我认为发生这种情况是因为 onSurfaceChanged 被调用了两次,但据我所知,我对此无能为力。

在我使用的渲染器中:

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    if (b_GameRunning) {
        // mark the fact that textures need reloading
        b_SurfaceWasChanged = true; 
    }
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
    gl.glMatrixMode( GL_PROJECTION );
    gl.glLoadIdentity();
    n_width = w;
    n_height = h;
    gl.glOrthof(0.f, (float)m_width, (float)m_height, 0.f, -1.f, 1.0f);
}

public void onDrawFrame(GL10 gl) {
    if (m_bGameRunning) {
        if (b_SurfaceWasChanged) {
            b_SurfaceWasChanged = false;
            ReloadTextures();
        }
        GameRender();
    }
}

非常感谢harism

我把onSurfaceChanged改成了:

public void onSurfaceChanged(GL10 gl, int w, int h) {
    n_width = w;
    n_height = h;
    gl.glViewport(0, 0, n_width, n_height);
    gl.glMatrixMode( GL_PROJECTION );
    gl.glLoadIdentity();
    gl.glOrthof(0.f, (float)m_width, (float)m_height, 0.f, -1.f, 1.0f);
}