Search in sources :

Example 1 with LegacyApplication

use of com.jme3.app.LegacyApplication in project jmonkeyengine by jMonkeyEngine.

the class AndroidHarness method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    initializeLogHandler();
    logger.fine("onCreate");
    super.onCreate(savedInstanceState);
    if (screenFullScreen) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
        if (!screenShowTitle) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
        }
    }
    final DataObject data = (DataObject) getLastNonConfigurationInstance();
    if (data != null) {
        logger.log(Level.FINE, "Using Retained App");
        this.app = data.app;
    } else {
        // Discover the screen reolution
        //TODO try to find a better way to get a hand on the resolution
        WindowManager wind = this.getWindowManager();
        Display disp = wind.getDefaultDisplay();
        Log.d("AndroidHarness", "Resolution from Window, width:" + disp.getWidth() + ", height: " + disp.getHeight());
        // Create Settings
        logger.log(Level.FINE, "Creating settings");
        AppSettings settings = new AppSettings(true);
        settings.setEmulateMouse(mouseEventsEnabled);
        settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY);
        settings.setUseJoysticks(joystickEventsEnabled);
        settings.setEmulateKeyboard(keyEventsEnabled);
        settings.setBitsPerPixel(eglBitsPerPixel);
        settings.setAlphaBits(eglAlphaBits);
        settings.setDepthBits(eglDepthBits);
        settings.setSamples(eglSamples);
        settings.setStencilBits(eglStencilBits);
        settings.setResolution(disp.getWidth(), disp.getHeight());
        settings.setAudioRenderer(audioRendererType);
        settings.setFrameRate(frameRate);
        // Create application instance
        try {
            if (app == null) {
                @SuppressWarnings("unchecked") Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
                app = clazz.newInstance();
            }
            app.setSettings(settings);
            app.start();
        } catch (Exception ex) {
            handleError("Class " + appClass + " init failed", ex);
            setContentView(new TextView(this));
        }
    }
    ctx = (OGLESContext) app.getContext();
    view = ctx.createView(this);
    // store the glSurfaceView in JmeAndroidSystem for future use
    JmeAndroidSystem.setView(view);
    // AndroidHarness wraps the app as a SystemListener.
    ctx.setSystemListener(this);
    layoutDisplay();
}
Also used : AppSettings(com.jme3.system.AppSettings) TextView(android.widget.TextView)

Example 2 with LegacyApplication

use of com.jme3.app.LegacyApplication in project jmonkeyengine by jMonkeyEngine.

the class AndroidHarnessFragment method onCreate.

/**
     * This Fragment uses setRetainInstance(true) so the onCreate method will only
     * be called once. During device configuration changes, the instance of
     * this Fragment will be reused in the new Activity.  This method should not
     * contain any View related objects.  They are created and destroyed by
     * other methods.  View related objects should not be reused, but rather
     * created and destroyed along with the Activity.
     *
     * @param savedInstanceState
     */
@Override
public void onCreate(Bundle savedInstanceState) {
    initializeLogHandler();
    logger.fine("onCreate");
    super.onCreate(savedInstanceState);
    // Create Settings
    logger.log(Level.FINE, "Creating settings");
    AppSettings settings = new AppSettings(true);
    settings.setEmulateMouse(mouseEventsEnabled);
    settings.setEmulateMouseFlipAxis(mouseEventsInvertX, mouseEventsInvertY);
    settings.setUseJoysticks(joystickEventsEnabled);
    settings.setEmulateKeyboard(keyEventsEnabled);
    settings.setBitsPerPixel(eglBitsPerPixel);
    settings.setAlphaBits(eglAlphaBits);
    settings.setDepthBits(eglDepthBits);
    settings.setSamples(eglSamples);
    settings.setStencilBits(eglStencilBits);
    settings.setAudioRenderer(audioRendererType);
    settings.setFrameRate(frameRate);
    // Create application instance
    try {
        if (app == null) {
            @SuppressWarnings("unchecked") Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
            app = clazz.newInstance();
        }
        app.setSettings(settings);
        app.start();
    } catch (Exception ex) {
        handleError("Class " + appClass + " init failed", ex);
    }
    OGLESContext ctx = (OGLESContext) app.getContext();
    // AndroidHarness wraps the app as a SystemListener.
    ctx.setSystemListener(this);
    setRetainInstance(true);
}
Also used : AppSettings(com.jme3.system.AppSettings) OGLESContext(com.jme3.system.android.OGLESContext)

Example 3 with LegacyApplication

use of com.jme3.app.LegacyApplication in project jmonkeyengine by jMonkeyEngine.

the class TestCanvas method createCanvas.

public static void createCanvas(String appClass) {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    }
    app.setPauseOnLostFocus(false);
    app.setSettings(settings);
    app.createCanvas();
    app.startCanvas();
    context = (JmeCanvasContext) app.getContext();
    canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
}
Also used : AppSettings(com.jme3.system.AppSettings) LegacyApplication(com.jme3.app.LegacyApplication)

Example 4 with LegacyApplication

use of com.jme3.app.LegacyApplication in project jmonkeyengine by jMonkeyEngine.

the class TestApplet method createCanvas.

public static void createCanvas(String appClass) {
    AppSettings settings = new AppSettings(true);
    settings.setWidth(640);
    settings.setHeight(480);
    //        settings.setRenderer(AppSettings.JOGL);
    JmeSystem.setLowPermissions(true);
    try {
        Class<? extends LegacyApplication> clazz = (Class<? extends LegacyApplication>) Class.forName(appClass);
        app = clazz.newInstance();
    } catch (ClassNotFoundException ex) {
        ex.printStackTrace();
    } catch (InstantiationException ex) {
        ex.printStackTrace();
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
    }
    app.setSettings(settings);
    app.createCanvas();
    context = (JmeCanvasContext) app.getContext();
    canvas = context.getCanvas();
    canvas.setSize(settings.getWidth(), settings.getHeight());
}
Also used : AppSettings(com.jme3.system.AppSettings) LegacyApplication(com.jme3.app.LegacyApplication)

Example 5 with LegacyApplication

use of com.jme3.app.LegacyApplication in project jmonkeyengine by jMonkeyEngine.

the class TestApplication method main.

public static void main(String[] args) throws InterruptedException {
    System.out.println("Creating application..");
    LegacyApplication app = new LegacyApplication();
    System.out.println("Starting application in LWJGL mode..");
    app.start();
    System.out.println("Waiting 5 seconds");
    Thread.sleep(5000);
    System.out.println("Closing application..");
    app.stop();
    Thread.sleep(2000);
    System.out.println("Starting in fullscreen mode");
    app = new LegacyApplication();
    AppSettings settings = new AppSettings(true);
    settings.setFullscreen(true);
    // current width/height
    settings.setResolution(-1, -1);
    app.setSettings(settings);
    app.start();
    Thread.sleep(5000);
    app.stop();
    Thread.sleep(2000);
    System.out.println("Creating offscreen buffer application");
    app = new LegacyApplication();
    app.start(Type.OffscreenSurface);
    Thread.sleep(3000);
    System.out.println("Destroying offscreen buffer");
    app.stop();
}
Also used : AppSettings(com.jme3.system.AppSettings) LegacyApplication(com.jme3.app.LegacyApplication)

Aggregations

AppSettings (com.jme3.system.AppSettings)8 LegacyApplication (com.jme3.app.LegacyApplication)5 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 TextView (android.widget.TextView)1 OGLESContext (com.jme3.system.android.OGLESContext)1