Search in sources :

Example 11 with AppSettings

use of com.jme3.system.AppSettings in project jmonkeyengine by jMonkeyEngine.

the class VRAppState method stateAttached.

@Override
public void stateAttached(AppStateManager stateManager) {
    //To change body of generated methods, choose Tools | Templates.
    super.stateAttached(stateManager);
    if (settings == null) {
        settings = new AppSettings(true);
        logger.config("Using default settings.");
    } else {
        logger.config("Using given settings.");
    }
    // Attach VR environment to the application
    if (!environment.isInitialized()) {
        environment.initialize();
    }
    if (environment.isInitialized()) {
        environment.atttach(this, stateManager.getApplication());
    } else {
        logger.severe("Cannot attach VR environment to the VR app state as its not initialized.");
    }
    GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
    if (environment.isInVR() && !environment.compositorAllowed()) {
        // "easy extended" mode
        // setup experimental JFrame on external device
        // first, find the VR device
        GraphicsDevice VRdev = null;
        GraphicsDevice[] devs = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        // pick the display that isn't the default one
        for (GraphicsDevice gd : devs) {
            if (gd != defDev) {
                VRdev = gd;
                break;
            }
        }
        // did we get the VR device?
        if (VRdev != null) {
            // set properties for VR acceleration
            try {
                java.awt.DisplayMode useDM = null;
                int max = 0;
                for (java.awt.DisplayMode dm : VRdev.getDisplayModes()) {
                    int check = dm.getHeight() + dm.getWidth() + dm.getRefreshRate() + dm.getBitDepth();
                    if (check > max) {
                        max = check;
                        useDM = dm;
                    }
                }
                // create a window for the VR device
                settings.setWidth(useDM.getWidth());
                settings.setHeight(useDM.getHeight());
                settings.setBitsPerPixel(useDM.getBitDepth());
                settings.setFrequency(useDM.getRefreshRate());
                settings.setSwapBuffers(true);
                // allow vsync on this display
                settings.setVSync(true);
                stateManager.getApplication().setSettings(settings);
                logger.config("Updated underlying application settings.");
                // make sure we are in the right display mode
                if (VRdev.getDisplayMode().equals(useDM) == false) {
                    VRdev.setDisplayMode(useDM);
                }
                return;
            } catch (Exception e) {
                logger.log(Level.SEVERE, e.getMessage(), e);
            }
        } else {
            logger.config("Cannot access to external screen.");
        }
    } else {
        if (!environment.isInVR()) {
            logger.config("Cannot switch to VR mode (VR disabled by user).");
        } else if (!environment.compositorAllowed()) {
            logger.warning("Cannot switch to VR mode (VR not supported).");
        }
    }
    if (!environment.isInVR()) {
        //FIXME: Handling GLFW workaround on MacOS
        boolean macOs = false;
        if (macOs) {
            // GLFW workaround on macs
            settings.setFrequency(defDev.getDisplayMode().getRefreshRate());
            settings.setDepthBits(24);
            settings.setVSync(true);
            // try and read resolution from file in local dir
            File resfile = new File("resolution.txt");
            if (resfile.exists()) {
                try {
                    BufferedReader br = new BufferedReader(new FileReader(resfile));
                    settings.setWidth(Integer.parseInt(br.readLine()));
                    settings.setHeight(Integer.parseInt(br.readLine()));
                    try {
                        settings.setFullscreen(br.readLine().toLowerCase(Locale.ENGLISH).contains("full"));
                    } catch (Exception e) {
                        settings.setFullscreen(false);
                    }
                    br.close();
                } catch (Exception e) {
                    settings.setWidth(1280);
                    settings.setHeight(720);
                }
            } else {
                settings.setWidth(1280);
                settings.setHeight(720);
                settings.setFullscreen(false);
            }
            settings.setResizable(false);
        }
        settings.setSwapBuffers(true);
    } else {
        // use basic mirroring window, skip settings window
        settings.setSamples(1);
        settings.setWidth(xWin);
        settings.setHeight(yWin);
        settings.setBitsPerPixel(32);
        settings.setFrameRate(0);
        settings.setFrequency(environment.getVRHardware().getDisplayFrequency());
        settings.setFullscreen(false);
        // stop vsyncing on primary monitor!
        settings.setVSync(false);
        settings.setSwapBuffers(environment.isSwapBuffers());
    }
    // Updating application settings
    stateManager.getApplication().setSettings(settings);
    logger.config("Updated underlying application settings.");
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) AppSettings(com.jme3.system.AppSettings) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File)

Example 12 with AppSettings

use of com.jme3.system.AppSettings in project jmonkeyengine by jMonkeyEngine.

the class JmeDesktopSystem method newAudioRenderer.

@Override
public AudioRenderer newAudioRenderer(AppSettings settings) {
    initialize(settings);
    AL al;
    ALC alc;
    EFX efx;
    if (settings.getAudioRenderer().startsWith("LWJGL")) {
        al = newObject("com.jme3.audio.lwjgl.LwjglAL");
        alc = newObject("com.jme3.audio.lwjgl.LwjglALC");
        efx = newObject("com.jme3.audio.lwjgl.LwjglEFX");
    } else if (settings.getAudioRenderer().startsWith("JOAL")) {
        al = newObject("com.jme3.audio.joal.JoalAL");
        alc = newObject("com.jme3.audio.joal.JoalALC");
        efx = newObject("com.jme3.audio.joal.JoalEFX");
    } else {
        throw new UnsupportedOperationException("Unrecognizable audio renderer specified: " + settings.getAudioRenderer());
    }
    if (al == null || alc == null || efx == null) {
        return null;
    }
    return new ALAudioRenderer(al, alc, efx);
}
Also used : EFX(com.jme3.audio.openal.EFX) ALC(com.jme3.audio.openal.ALC) AL(com.jme3.audio.openal.AL) ALAudioRenderer(com.jme3.audio.openal.ALAudioRenderer)

Example 13 with AppSettings

use of com.jme3.system.AppSettings in project jmonkeyengine by jMonkeyEngine.

the class TestVertexBufferSharing method main.

public static void main(String[] args) {
    TestVertexBufferSharing app = new TestVertexBufferSharing();
    AppSettings settings = new AppSettings(true);
    settings.setOpenCLSupport(true);
    settings.setVSync(false);
    //        settings.setRenderer(AppSettings.JOGL_OPENGL_FORWARD_COMPATIBLE);
    app.setSettings(settings);
    // start the game
    app.start();
}
Also used : AppSettings(com.jme3.system.AppSettings)

Example 14 with AppSettings

use of com.jme3.system.AppSettings in project jmonkeyengine by jMonkeyEngine.

the class TestWriteToTexture method main.

public static void main(String[] args) {
    TestWriteToTexture app = new TestWriteToTexture();
    AppSettings settings = new AppSettings(true);
    settings.setOpenCLSupport(true);
    settings.setVSync(false);
    //        settings.setRenderer(AppSettings.JOGL_OPENGL_FORWARD_COMPATIBLE);
    app.setSettings(settings);
    // start the game
    app.start();
}
Also used : AppSettings(com.jme3.system.AppSettings)

Example 15 with AppSettings

use of com.jme3.system.AppSettings in project jmonkeyengine by jMonkeyEngine.

the class TestOpenCLLibraries method main.

public static void main(String[] args) {
    TestOpenCLLibraries app = new TestOpenCLLibraries();
    AppSettings settings = new AppSettings(true);
    settings.setOpenCLSupport(true);
    settings.setVSync(true);
    //        settings.setRenderer(AppSettings.JOGL_OPENGL_FORWARD_COMPATIBLE);
    app.setSettings(settings);
    // start the game
    app.start();
}
Also used : AppSettings(com.jme3.system.AppSettings)

Aggregations

AppSettings (com.jme3.system.AppSettings)40 LegacyApplication (com.jme3.app.LegacyApplication)5 IOException (java.io.IOException)4 AL (com.jme3.audio.openal.AL)3 ALAudioRenderer (com.jme3.audio.openal.ALAudioRenderer)3 ALC (com.jme3.audio.openal.ALC)3 EFX (com.jme3.audio.openal.EFX)2 MouseInput (com.jme3.input.MouseInput)2 Vector2f (com.jme3.math.Vector2f)2 Mesh (com.jme3.scene.Mesh)2 JmeToJFXApplication (com.jme3x.jfx.injfx.JmeToJFXApplication)2 GraphicsDevice (java.awt.GraphicsDevice)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStream (java.io.InputStream)2 TextView (android.widget.TextView)1 JmeUtil (com.cas.sim.tis.util.JmeUtil)1 SettingsDialog (com.jme3.app.SettingsDialog)1 SelectionListener (com.jme3.app.SettingsDialog.SelectionListener)1 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)1