From 4f75cb688fc24e4b291e4780ce912198624b5634 Mon Sep 17 00:00:00 2001 From: "iwg..ic" Date: Tue, 26 Nov 2013 02:20:42 +0000 Subject: [PATCH] Android: Move application initialization to the first onDrawFrame. Resolves issues where simpleInitApp gets called without the correct appsettings width and height. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10917 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/system/android/OGLESContext.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/engine/src/android/com/jme3/system/android/OGLESContext.java b/engine/src/android/com/jme3/system/android/OGLESContext.java index 6ed285831..345fbf9b8 100644 --- a/engine/src/android/com/jme3/system/android/OGLESContext.java +++ b/engine/src/android/com/jme3/system/android/OGLESContext.java @@ -176,7 +176,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex renderer.resetGLObjects(); } else { if (!created.get()) { - logger.fine("GL Surface created, doing JME3 init"); + logger.fine("GL Surface created, initializing JME3 renderer"); initInThread(); } else { logger.warning("GL Surface already created"); @@ -201,12 +201,10 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex renderer = new OGLESShaderRenderer(); renderer.initialize(); - listener.initialize(); JmeSystem.setSoftTextDialogInput(this); needClose.set(false); - renderable.set(true); } /** @@ -302,8 +300,17 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex @Override public void onSurfaceChanged(GL10 gl, int width, int height) { logger.log(Level.FINE, "GL Surface changed, width: {0} height: {1}", new Object[]{width, height}); + // update the application settings with the new resolution settings.setResolution(width, height); - listener.reshape(width, height); + // reload settings in androidInput so the correct touch event scaling can be + // calculated in case the surface resolution is different than the view + androidInput.loadSettings(settings); + // if the application has already been initialized (ie renderable is set) + // then call reshape so the app can adjust to the new resolution. + if (renderable.get()) { + logger.log(Level.FINE, "App already initialized, calling reshape"); + listener.reshape(width, height); + } } // SystemListener:update @@ -314,7 +321,13 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex return; } - if (renderable.get()) { + if (!renderable.get()) { + if (created.get()) { + logger.fine("GL Surface is setup, initializing application"); + listener.initialize(); + renderable.set(true); + } + } else { if (!created.get()) { throw new IllegalStateException("onDrawFrame without create"); }