0

Working on a game that only runs in Portrait mode, I tried forcing sensorPortrait via the manifest:

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

But when I lock the device in portrait, rotate it to landscape and then unlock it this happens:

landscape

And this is How it looks in portrait:

portrait

I think this happens because onSurfaceChanged is called twice but AFAIK there's nothing I can really do about that.

In the renderer I use:

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();
    }
}
crstn.udrea
  • 103
  • 1
  • 8
  • 1
    You could try calling _glViewport_ just in case with new width and height. It looks a bit confusing state your rendering happens in though. – harism Feb 20 '15 at 11:50
  • Yep, I pretty much needed to call `gl.glViewport` in `onSurfaceChanged` before anything else so I changed it accordingly. The rendering looks like this I can't post the actual code, it's an approximation. – crstn.udrea Feb 20 '15 at 11:58

1 Answers1

1

Many Thanks to harism.

I changed onSurfaceChanged to:

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);
}
crstn.udrea
  • 103
  • 1
  • 8