| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>jME3 Application Display Settings</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"><link rel="stylesheet" href="/home/travis/build/jMonkeyEngine/wiki/build/asciidoc/html5/jme3/intermediate/twemoji-awesome.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/jme3/intermediate/appsettings.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/jme3/intermediate/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>jME3 Application Display Settings</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#code-samples">Code Samples</a></li><li><a href="#properties">Properties</a></li><li><a href="#toggling-and-activating-settings">Toggling and Activating Settings</a></li><li><a href="#saving-and-loading-settings">Saving and Loading Settings</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="paragraph"><p>Every class that extends jme3.app.SimpleApplication has properties that can be configured by customizing a <code>com.jme3.system.AppSettings</code> object.</p></div>
- <div class="admonitionblock important"><table><tr><td class="icon"><i class="fa icon-important" title="Important"></i></td><td class="content"><div class="paragraph"><p>Configure application settings in <code>main()</code>, before you call <code>app.start()</code> on the application object. If you change display settings during runtime, for example in <code>simpleInitApp()</code>, you must call <code>app.restart()</code> to make them take effect.</p></div></td></tr></table></div>
- <div class="paragraph"><p><strong>Note:</strong> Other runtime settings are covered in <a href="../../jme3/intermediate/simpleapplication.html">SimpleApplication</a>.</p></div></div></div>
- <div class="sect1"><h2 id="code-samples">Code Samples</h2><div class="sectionbody"><div class="paragraph"><p>Specify settings for a game (here called <code>MyGame</code>, or whatever you called your SimpleApplication instance) in the <code>main()</code> method before the game starts:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="directive">static</span> <span class="type">void</span> main(<span class="predefined-type">String</span><span class="type">[]</span> args) {
- AppSettings settings = <span class="keyword">new</span> AppSettings(<span class="predefined-constant">true</span>);
- settings.setResolution(<span class="integer">640</span>,<span class="integer">480</span>);
- <span class="comment">// ... other properties, see below</span>
- MyGame app = <span class="keyword">new</span> MyGame();
- app.setSettings(settings);
- app.start();
- }</code></pre></div></div>
- <div class="paragraph"><p>Set the boolean in the AppSettings contructor to true if you want to keep the default settings for values that you do not specify. Set this parameter to false if you want the application to load user settings from previous launches. In either case you can still customize individual settings.</p></div>
- <div class="admonitionblock warning"><table><tr><td class="icon"><i class="fa icon-warning" title="Warning"></i></td><td class="content">The settings are saved based on the title of your game (default = “jMonkey Engine 3.x-stable”). This means that if you have not changed the default title, then remove a setting method call, your settings changes will remain in effect for all projects using the default title. To prevent this, set the title for your game or remember to change the settings back to their <a href="https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/system/AppSettings.java#L213">default</a> and run the project again.</td></tr></table></div>
- <div class="paragraph"><p>This example toggles the settings to fullscreen while the game is already running. Then it restarts the game context (not the whole game) which applies the changed settings.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"><span class="directive">public</span> <span class="type">void</span> toggleToFullscreen() {
- <span class="predefined-type">GraphicsDevice</span> device = <span class="predefined-type">GraphicsEnvironment</span>.getLocalGraphicsEnvironment().getDefaultScreenDevice();
- <span class="predefined-type">DisplayMode</span><span class="type">[]</span> modes = device.getDisplayModes();
- <span class="type">int</span> i=<span class="integer">0</span>; <span class="comment">// note: there are usually several, let's pick the first</span>
- settings.setResolution(modes[i].getWidth(),modes[i].getHeight());
- settings.setFrequency(modes[i].getRefreshRate());
- settings.setBitsPerPixel(modes[i].getBitDepth());
- settings.setFullscreen(device.isFullScreenSupported());
- app.setSettings(settings);
- app.restart(); <span class="comment">// restart the context to apply changes</span>
- }</code></pre></div></div>
- <div class="paragraph"><p>To view your current settings, use the System class.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">AppSettings settings = <span class="keyword">new</span> AppSettings(<span class="predefined-constant">true</span>);
- <span class="predefined-type">System</span>.out.println(settings);</code></pre></div></div></div></div>
- <div class="sect1"><h2 id="properties">Properties</h2><div class="sectionbody"><table class="tableblock frame-all grid-all spread"><caption class="title">Table A: Video</caption><colgroup><col style="width: 30%;"><col style="width: 55%;"><col style="width: 15%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Settings Property</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Default</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setRenderer(AppSettings.LWJGL_OPENGL1)<br>
- setRenderer(AppSettings.LWJGL_OPENGL2)<br>
- setRenderer(AppSettings.LWJGL_OPENGL3)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Switch Video Renderer to OpenGL 1.1, OpenGL 2, or OpenGL 3.3. If your graphic card does not support all OpenGL2 features (<code>UnsupportedOperationException: GLSL and OpenGL2 is required for the LWJGL renderer</code>), then you can force your SimpleApplication to use OpenGL1 compatibility. (Then you still can’t use special OpenGL2 features, but at least the error goes away and you can continue with the rest.)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>OpenGL 2</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setBitsPerPixel(32)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Set the color depth.<br>
- 1 bpp = black and white, 2 bpp = gray,<br>
- 4 bpp = 16 colors, 8 bpp = 256 colors, 24 or 32 bpp = “truecolor”.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>24</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setFramerate(60)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>How often per second the engine should try to refresh the frame. For the release, usually 60 fps. Can be lower (30) if you need to free up the CPU for other applications. No use setting it to a higher value than the screen frequency! If the framerate goes below 30 fps, viewers start to notice choppiness or flickering.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>-1 (unlimited)</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setFullscreen(true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Set this to true to make the game window fill the whole screen; you need to provide a key that calls app.stop() to exit the fullscreen view gracefully (default: escape).<br>
- Set this to false to play the game in a normal window of its own.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>False (windowed)</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setHeight(480), setWidth(640)<br>
- setResolution(640,480)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Two equivalent ways of setting the display resolution.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>640x480 pixels</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setSamples(4)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Set multisampling to 0 to switch antialiasing off (harder edges, faster.)<br>
- Set multisampling to 2 or 4 to activate antialising (softer edges, may be slower.)<br>
- Depending on your graphic card, you may be able to set multisampling to higher values such as 8, 16, or 32 samples.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>0</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setVSync(true)<br>
- setFrequency(60)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Set vertical syncing to true to time the frame buffer to coincide with the refresh frequency of the screen. VSync prevents ugly page tearing artefacts, but is a bit slower; recommened for release build.<br>
- Set VSync to false to deactivate vertical syncing (faster, but possible page tearing artifacts); can remain deactivated during development or for slower PCs.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false<br>
- 60 fps</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setStencilBits(8)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Set the number of stencil bits.<br>
- This value is only relevant when the stencil buffer is being used. Specify 8 to indicate an 8-bit stencil buffer, specify 0 to disable the stencil buffer.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>0 (disabled)</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setDepthBits(16)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Sets the number of depth bits to use.<br>
- The number of depth bits specifies the precision of the depth buffer. To increase precision, specify 32 bits. To decrease precision, specify 16 bits. On some platforms 24 bits might not be supported, in that case, specify 16 bits.<br>
- See <a href="https://msdn.microsoft.com/en-us/library/bb976071.aspx">What Is a Depth Buffer?</a> and <a href="https://en.wikipedia.org/wiki/Z-buffering">Z-buffering</a> for a more in depth explanation.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>24</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setGammaCorrection(true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Enables Gamma Correction.<br>
- If you’re starting a new project, use it, period. And don’t allow the player to turn it off.<br>
- See <a href="../../jme3/advanced/jme3_srgbpipeline.html">Gamma Correction or sRGB pipeline</a></p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false</p></div></div></td></tr></tbody></table>
- <table class="tableblock frame-all grid-all spread"><caption class="title">Table B: Input</caption><colgroup><col style="width: 30%;"><col style="width: 55%;"><col style="width: 15%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Settings Property</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Default</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setUseInput(false)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Respond to user input by mouse and keyboard. Can be deactivated for use cases where you only display a 3D scene on the canvas without any interaction.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>true</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setUseJoysticks(true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Activate optional joystick support</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setEmulateMouse(true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Enable or disable mouse emulation for touchscreen-based devices. Setting this to true converts taps on the touchscreen to clicks, and finger swiping gestures over the touchscreen into mouse axis events.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setEmulateMouseFlipAxis(true,true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Flips the X or Y (or both) axes for the emulated mouse. Set the first parameter to true to flip the x axis, and the second to flip the y axis.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false,false</p></div></div></td></tr></tbody></table>
- <table class="tableblock frame-all grid-all spread"><caption class="title">Table C: Audio</caption><colgroup><col style="width: 30%;"><col style="width: 55%;"><col style="width: 15%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Settings Property</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Default</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setAudioRenderer(AppSettings.LWJGL_OPENAL)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Switch Audio Renderer. Currently there is only one option.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>OpenAL</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setStereo3D(true)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Enable 3D stereo. This feature requires hardware support from the GPU driver. See <a href="http://en.wikipedia.org/wiki/Quad_buffering">Quad Buffering</a>. Currently, your everday user’s hardware does not support this, so you can ignore it for now.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>false</p></div></div></td></tr></tbody></table>
- <table class="tableblock frame-all grid-all spread"><caption class="title">Table D: Branding</caption><colgroup><col style="width: 30%;"><col style="width: 55%;"><col style="width: 15%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">Settings Property</th><th class="tableblock halign-left valign-top">Description</th><th class="tableblock halign-left valign-top">Default</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setTitle("My Game")</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>This string will be visible in the titlebar, unless the window is fullscreen.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>“jMonkey Engine 3.x-stable”</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setIcons(new BufferedImage[]{<br>
- ImageIO.read(new File(" ")), …});</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>This specifies the little application icon in the titlebar of the application (unused in MacOS?). You should specify the icon in various sizes (256,128,32,16) to look good on various operating systems. Note: This is not the application icon on the desktop.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>null</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>setSettingsDialogImage("Interface/mysplashscreen.png")</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>A custom splashscreen image in the <code>assets/Interface</code> directory which is displayed when the settings dialog is shown.</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>"/com/jme3/app/Monkey.png"</p></div></div></td></tr></tbody></table>
- <div class="admonitionblock tip"><table><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><div class="paragraph"><p>You can use <code>app.setShowSettings(true);</code> and <code>setSettingsDialogImage("Interface/mysplashscreen.png")</code> to present the user with jme3’s default display settings dialog when starting the game. Use <code>app.setShowSettings(false);</code> to hide the default settings screen. Set this boolean before calling <code>app.start()</code> on the SimpleApplication.</p></div></td></tr></table></div></div></div>
- <div class="sect1"><h2 id="toggling-and-activating-settings">Toggling and Activating Settings</h2><div class="sectionbody"><table class="tableblock frame-all grid-all spread"><colgroup><col style="width: 25%;"><col style="width: 75%;"></colgroup><thead><tr><th class="tableblock halign-left valign-top">SimpleApplication method</th><th class="tableblock halign-left valign-top">Description</th></tr></thead><tbody><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>app.setShowSettings(boolean)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Activate or deactivate the default settings screen before start()ing the game. If you let users use this screen, you do not need to modify the settings object. Note: Most developers implement their own custom settings screen, but the default one is useful during the alpha stages.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>app.setSettings(settings)</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>After you have modified the properties on the settings object, you apply it to your application. Note that the settings are not automatically reloaded while the game is running.</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>app.start()</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Every game calls start() in the beginning to initialize the game and apply the settings. Modify and set your settings before calling start().</p></div></div></td></tr><tr><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>app.restart()</p></div></div></td><td class="tableblock halign-left valign-top"><div><div class="paragraph"><p>Restart()ing a running game restarts the game context and applies the updated settings object. (This does not restart or reinitialize the whole game.)</p></div></div></td></tr></tbody></table></div></div>
- <div class="sect1"><h2 id="saving-and-loading-settings">Saving and Loading Settings</h2><div class="sectionbody"><div class="admonitionblock caution"><table><tr><td class="icon"><i class="fa icon-caution" title="Caution"></i></td><td class="content"><div class="paragraph"><p>Due to a current bug and inconsistent behavior observed related to the preferences save location, to ensure correct behavior, save() and load() should only use forward slashes <kbd>/</kbd> and must be all lowercase.</p></div>
- <div class="paragraph"><p>More information can be found <a href="https://github.com/jMonkeyEngine/jmonkeyengine/issues/1161">here</a>.</p></div></td></tr></table></div>
- <div class="paragraph"><p>An AppSettings object also supports the following methods to save your settings under a unique key (in this example “com/foo/mycoolgame3”):</p></div>
- <div class="ulist"><ul><li><p>Use <code>settings.save("com/foo/mycoolgame3")</code> to save your settings via standard java.io serialization.</p></li><li><p>Use <code>settings.load("com/foo/mycoolgame3")</code> to load your settings.</p></li><li><p>Use <code>settings2.copyFrom(settings)</code> to copy a settings object.</p></li></ul></div>
- <div class="paragraph"><p>Usage:</p></div>
- <div class="paragraph"><p>Provide the unique name of your jME3 application as the String argument. For example <code>com/foo/mycoolgame3</code>.</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java"> <span class="keyword">try</span> { settings.save(<span class="string"><span class="delimiter">"</span><span class="content">com/foo/mycoolgame3</span><span class="delimiter">"</span></span>); }
- <span class="keyword">catch</span> (<span class="exception">BackingStoreException</span> ex) { <span class="comment">/** could not save settings */</span> }</code></pre></div></div>
- <div class="ulist"><ul><li><p>On Windows, the preferences are saved under the following registry key:<br>
- <code>HKEY_CURRENT_USER\Software\JavaSoft\Prefs\com\foo\mycoolgame3</code></p></li><li><p>On Linux, the preferences are saved in an XML file under:<br>
- <code>$HOME/.java/.userPrefs/com/foo/mycoolgame3</code></p></li><li><p>On Mac <abbr title="Operating System">OS</abbr> X, the preferences are saved as XML file under:<br>
- <code>$HOME/Library/Preferences/com.foo.mycoolgame3.plist</code></p></li></ul></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2020-05-21 00:29:23 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
- apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
- indexName: 'jmonkeyengine',
- inputSelector: '#doc-search',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|