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.");
}
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);
}
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();
}
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();
}
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();
}
Aggregations