com.jme3.system.JmeSystem Java Examples

The following examples show how to use com.jme3.system.JmeSystem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleApplication.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void start() {
    // set some default settings in-case
    // settings dialog is not shown
    boolean loadSettings = false;
    if (settings == null) {
        setSettings(new AppSettings(true));
        loadSettings = true;
    }

    // show settings dialog
    if (showSettings) {
        if (!JmeSystem.showSettingsDialog(settings, loadSettings)) {
            return;
        }
    }
    //re-setting settings they can have been merged from the registry.
    setSettings(settings);
    super.start();
}
 
Example #2
Source File: EditableMaterialFile.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void initMatDef() {
    //try to read from assets folder
    matDef = manager.getAssetFolder().getFileObject(getMatDefName());

    //try to read from classpath if not in assets folder and store in a virtual filesystem folder
    if (matDef == null || !matDef.isValid()) {
        try {
            fs = FileUtil.createMemoryFileSystem();
            matDef = fs.getRoot().createData(name, "j3md");
            OutputStream out = matDef.getOutputStream();
            InputStream in = JmeSystem.getResourceAsStream("/" + getMatDefName());
            if (in != null) {
                int input = in.read();
                while (input != -1) {
                    out.write(input);
                    input = in.read();
                }
                in.close();
            }
            out.close();
        } catch (IOException ex) {
            Exceptions.printStackTrace(ex);
        }
    }
}
 
Example #3
Source File: SimpleApplication.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void start() {
    // set some default settings in-case
    // settings dialog is not shown
    boolean loadSettings = false;
    if (settings == null) {
        setSettings(new AppSettings(true));
        loadSettings = true;
    }

    // show settings dialog
    if (showSettings) {
        if (!JmeSystem.showSettingsDialog(settings, loadSettings)) {
            return;
        }
    }
    //re-setting settings they can have been merged from the registry.
    setSettings(settings);
    super.start();
}
 
Example #4
Source File: TextureUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * <code>uploadTextureBitmap</code> uploads a native android bitmap
 * @param target
 * @param bitmap
 * @param generateMips
 * @param powerOf2
 */
public static void uploadTextureBitmap(final int target, Bitmap bitmap, boolean generateMips, boolean powerOf2) {
    int MAX_RETRY_COUNT = 1;
    for(int retryCount = 0;retryCount<MAX_RETRY_COUNT;retryCount++) {
        try {
            uploadTextureBitmap2(target, bitmap, generateMips, powerOf2);
        }catch(OutOfMemoryError ex) {
            if (!(retryCount < MAX_RETRY_COUNT)){
                throw ex;
            }
            DesktopAssetManager assetManager = 
                    (DesktopAssetManager)((AndroidHarness)JmeSystem.getActivity())
                    .getJmeApplication().getAssetManager();
            assetManager.clearCache();
            System.gc();
            System.runFinalization();
        }
    }
}
 
Example #5
Source File: OpenRTSApplication.java    From OpenRTS with MIT License 6 votes vote down vote up
public void changeSettings() {
	JmeSystem.showSettingsDialog(settings, false);
	if (settings.isFullscreen()) {
		logger.info("Fullscreen not yet supported");
		settings.setFullscreen(false);
	}

	try {
		settings.save("openrts.example");
	} catch (BackingStoreException e) {
		throw new TechnicalException(e);
	}
	appInstance.setSettings(settings);
	appInstance.restart(); // restart the context to apply changes
	cam.resize(settings.getWidth(), settings.getHeight(), true);
}
 
Example #6
Source File: CollideIgnoreTransformTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testPhantomTriangles() {
    JmeSystem.setSystemDelegate(new MockJmeSystemDelegate());
    assetManager = new DesktopAssetManager();
    assetManager.registerLocator(null, ClasspathLocator.class);
    assetManager.registerLoader(J3MLoader.class, "j3m", "j3md");
    rootNode = new Node();

    createRedSquare();

    rootNode.updateLogicalState(0.01f);
    rootNode.updateGeometricState();
    /**
     * ray in the -Z direction, starting from (0.5, 0.6, 10)
     */
    Ray ray1 = new Ray(/* origin */new Vector3f(0.5f, 0.6f, 10f),
            /* direction */ new Vector3f(0f, 0f, -1f));
    castRay(ray1, 1);
    /**
     * ray in the -Z direction, starting from (0.5, 3, 10)
     */
    Ray ray0 = new Ray(/* origin */new Vector3f(0.5f, 3f, 10f),
            /* direction */ new Vector3f(0f, 0f, -1f));
    castRay(ray0, 0);
}
 
Example #7
Source File: VRApplication.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Handle the error given in parameters by creating a log entry and a dialog window. Internal use only.
 */
@Override
public void handleError(String errMsg, Throwable t){
    // Print error to log.
    logger.log(Level.SEVERE, errMsg, t);
    // Display error message on screen if not in headless mode
    if (context.getType() != JmeContext.Type.Headless) {
        if (t != null) {
            JmeSystem.showErrorDialog(errMsg + "\n" + t.getClass().getSimpleName() +
                    (t.getMessage() != null ? ": " +  t.getMessage() : ""));
        } else {
            JmeSystem.showErrorDialog(errMsg);
        }
    }

    stop(); // stop the application
}
 
Example #8
Source File: ProgramCache.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates a new program cache associated with the specified context and
 * devices.
 * The cached programs are built against the specified device and also
 * only the binaries linked to that device are stored.
 * @param context the OpenCL context
 * @param device the OpenCL device
 */
public ProgramCache(Context context, Device device) {
    this.context = context;
    this.device = device;
    if (JmeSystem.isLowPermissions()) {
        tmpFolder = null;
    } else {
        tmpFolder = JmeSystem.getStorageFolder();
    }
}
 
Example #9
Source File: InputSystemJme.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void processSoftKeyboard() {
    SoftTextDialogInput softTextDialogInput = JmeSystem.getSoftTextDialogInput();
    if (softTextDialogInput != null) {
        Element element = nifty.getCurrentScreen().getFocusHandler().getKeyboardFocusElement();
        if (element != null) {
            final TextField textField = element.getNiftyControl(TextField.class);
            if (textField != null) {
                Logger.getLogger(InputSystemJme.class.getName()).log(Level.FINE, "Current TextField: {0}", textField.getId());
                String initialValue = textField.getRealText();
                if (initialValue == null) {
                    initialValue = "";
                }

                softTextDialogInput.requestDialog(SoftTextDialogInput.TEXT_ENTRY_DIALOG, "Enter Text", initialValue, new SoftTextDialogInputListener() {

                    @Override
                    public void onSoftText(int action, String text) {
                        if (action == SoftTextDialogInputListener.COMPLETE) {
                            textField.setText(text);
                        }
                    }
                });
            }
        }
    }

}
 
Example #10
Source File: Application.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void initAudio(){
    if (settings.getAudioRenderer() != null && context.getType() != Type.Headless){
        audioRenderer = JmeSystem.newAudioRenderer(settings);
        audioRenderer.initialize();
        AudioContext.setAudioRenderer(audioRenderer);

        listener = new Listener();
        audioRenderer.setListener(listener);
    }
}
 
Example #11
Source File: BaseAWTTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private AssetManager createAssetManager() {
    /* Desktop.cfg supports the following additional file formats at the time of writing:
        LOADER com.jme3.texture.plugins.AWTLoader : jpg, bmp, gif, png, jpeg
        LOADER com.jme3.audio.plugins.OGGLoader : ogg
     */
    return JmeSystem.newAssetManager(BaseTest.class.getResource("/com/jme3/asset/Desktop.cfg"));
}
 
Example #12
Source File: TestMusicPlayer.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void initAudioPlayer(){
    AppSettings settings = new AppSettings(true);
    settings.setRenderer(null); // disable rendering
    settings.setAudioRenderer("LWJGL");
    ar = JmeSystem.newAudioRenderer(settings);
    ar.initialize();
    ar.setListener(listener);
}
 
Example #13
Source File: LwjglAbstractDisplay.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Does LWJGL display initialization in the OpenGL thread
 */
protected void initInThread(){
    try{
        if (!JmeSystem.isLowPermissions()){
            // Enable uncaught exception handler only for current thread
            Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                public void uncaughtException(Thread thread, Throwable thrown) {
                    listener.handleError("Uncaught exception thrown in "+thread.toString(), thrown);
                    if (needClose.get()){
                        // listener.handleError() has requested the 
                        // context to close. Satisfy request.
                        deinitInThread();
                    }
                }
            });
        }

        // For canvas, this will create a pbuffer,
        // allowing us to query information.
        // When the canvas context becomes available, it will
        // be replaced seamlessly.
        createContext(settings);
        printContextInitInfo();

        created.set(true);
    } catch (Exception ex){
        try {
            if (Display.isCreated())
                Display.destroy();
        } catch (Exception ex2){
            logger.log(Level.WARNING, null, ex2);
        }

        listener.handleError("Failed to create display", ex);
        return; // if we failed to create display, do not continue
    }
    super.internalCreate();
    listener.initialize();
}
 
Example #14
Source File: AndroidApplication.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void initialize() 
{
    // Create a default Android assetmanager before Application can create one in super.initialize();
    assetManager = JmeSystem.newAssetManager(null);        
    super.initialize();

    guiNode.setQueueBucket(Bucket.Gui);
    guiNode.setCullHint(CullHint.Never);
    loadFPSText();
    viewPort.attachScene(rootNode);
    guiViewPort.attachScene(guiNode);
    
    inputManager.addMapping("TouchEscape", new TouchTrigger(TouchInput.KEYCODE_BACK));
    inputManager.addListener(this, new String[]{"TouchEscape"}); 

    // call user code
    init();
    
    // Start thread for async load
    Thread t = new Thread(new Runnable()
    {
        @Override
        public void run ()
        {
            try
            {
                // call user code
                asyncload();
            }
            catch (Exception e)
            {
                handleError("AsyncLoad failed", e);
            }
            loadingFinished.set(true);
        }
    });
    t.setDaemon(true);
    t.start();
}
 
Example #15
Source File: LoadShaderSourceTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testLoadShaderSource() {
    JmeSystem.setSystemDelegate(new MockJmeSystemDelegate());
    AssetManager assetManager = new DesktopAssetManager();
    assetManager.registerLocator(null, ClasspathLocator.class);
    assetManager.registerLoader(GLSLLoader.class, "frag");
    assetManager.registerLoader(GLSLLoader.class, "glsllib");
    assetManager.registerLoader(GLSLLoader.class, "glsl");
    String showNormals = (String) assetManager.loadAsset("Common/MatDefs/Misc/ShowNormals.frag");
    System.out.println(showNormals);
}
 
Example #16
Source File: ShaderCheck.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void initAssetManager(){
    assetManager = JmeSystem.newAssetManager();
    assetManager.registerLocator(".", FileLocator.class);
    assetManager.registerLocator("/", ClasspathLocator.class);
    assetManager.registerLoader(J3MLoader.class, "j3m");
    assetManager.registerLoader(J3MLoader.class, "j3md");
    assetManager.registerLoader(GLSLLoader.class, "vert", "frag","geom","tsctrl","tseval","glsllib","glsl");
}
 
Example #17
Source File: ScreenshotAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *  Called by postFrame() once the screen has been captured to outBuf.
 */
protected void writeImageFile( File file ) throws IOException {
    OutputStream outStream = new FileOutputStream(file);
    try {
        JmeSystem.writeImageFile(outStream, "png", outBuf, width, height);
    } finally {
        outStream.close();
    }
}
 
Example #18
Source File: ScreenshotAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void postFrame(FrameBuffer out) {
    if (capture){
        capture = false;

        Camera curCamera = rm.getCurrentCamera();
        int viewX = (int) (curCamera.getViewPortLeft() * curCamera.getWidth());
        int viewY = (int) (curCamera.getViewPortBottom() * curCamera.getHeight());
        int viewWidth = (int) ((curCamera.getViewPortRight() - curCamera.getViewPortLeft()) * curCamera.getWidth());
        int viewHeight = (int) ((curCamera.getViewPortTop() - curCamera.getViewPortBottom()) * curCamera.getHeight());

        renderer.setViewPort(0, 0, width, height);
        renderer.readFrameBuffer(out, outBuf);
        renderer.setViewPort(viewX, viewY, viewWidth, viewHeight);

        File file;
        String filename;
        if (numbered) {
            shotIndex++;
            filename = shotName + shotIndex;
        } else {
            filename = shotName;
        }

        if (filePath == null) {
            file = new File(JmeSystem.getStorageFolder() + File.separator + filename + ".png").getAbsoluteFile();
        } else {
            file = new File(filePath + filename + ".png").getAbsoluteFile();
        }
        logger.log(Level.FINE, "Saving ScreenShot to: {0}", file.getAbsolutePath());

        try {
            writeImageFile(file);
        } catch (IOException ex) {
            logger.log(Level.SEVERE, "Error while saving screenshot", ex);
        }                
    }
}
 
Example #19
Source File: EditorUtil.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Added files like files to copy to clipboard content.
 *
 * @param paths   the list of files.
 * @param content the content to store.
 */
@FxThread
public static @NotNull ClipboardContent addCopiedFile(
        @NotNull Array<Path> paths,
        @NotNull ClipboardContent content
) {

    var files = paths.stream()
            .map(Path::toFile)
            .collect(toList());

    content.putFiles(files);
    content.put(EditorUtil.JAVA_PARAM, "copy");

    var platform = JmeSystem.getPlatform();

    if (platform == Platform.Linux64 || platform == Platform.Linux32) {

        var builder = new StringBuilder("copy\n");

        paths.forEach(builder, (path, b) ->
                b.append(path.toUri().toASCIIString()).append('\n'));

        builder.delete(builder.length() - 1, builder.length());

        var buffer = ByteBuffer.allocate(builder.length());

        for (int i = 0, length = builder.length(); i < length; i++) {
            buffer.put((byte) builder.charAt(i));
        }

        buffer.flip();

        content.put(GNOME_FILES, buffer);
    }

    return content;
}
 
Example #20
Source File: TestActivity.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void toggleKeyboard(final boolean show) {
    fragment.getView().getHandler().post(new Runnable() {

        @Override
        public void run() {
            JmeSystem.showSoftKeyboard(show);
        }
    });

}
 
Example #21
Source File: VRApplication.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initAudio(){
    if (settings.getAudioRenderer() != null && context.getType() != JmeContext.Type.Headless){
        audioRenderer = JmeSystem.newAudioRenderer(settings);
        audioRenderer.initialize();
        AudioContext.setAudioRenderer(audioRenderer);

        listener = new Listener();
        audioRenderer.setListener(listener);
    }
}
 
Example #22
Source File: TestMusicPlayer.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initAudioPlayer(){
    AppSettings settings = new AppSettings(true);
    settings.setRenderer(null); // disable rendering
    settings.setAudioRenderer("LWJGL");
    ar = JmeSystem.newAudioRenderer(settings);
    ar.initialize();
    ar.setListener(listener);
    AudioContext.setAudioRenderer(ar);
}
 
Example #23
Source File: TestAbsoluteLocators.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String[] args){
    AssetManager am = JmeSystem.newAssetManager();

    am.registerLoader(AWTLoader.class, "jpg");
    am.registerLoader(WAVLoader.class, "wav");

    // register absolute locator
    am.registerLocator("/",  ClasspathLocator.class);

    // find a sound
    AudioData audio = am.loadAudio("Sound/Effects/Gun.wav");

    // find a texture
    Texture tex = am.loadTexture("Textures/Terrain/Pond/Pond.jpg");

    if (audio == null)
        throw new RuntimeException("Cannot find audio!");
    else
        System.out.println("Audio loaded from Sounds/Effects/Gun.wav");

    if (tex == null)
        throw new RuntimeException("Cannot find texture!");
    else
        System.out.println("Texture loaded from Textures/Terrain/Pond/Pond.jpg");

    System.out.println("Success!");
}
 
Example #24
Source File: LwjglAbstractDisplay.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Does LWJGL display initialization in the OpenGL thread
 */
protected boolean initInThread() {
    try {
        if (!JmeSystem.isLowPermissions()) {
            // Enable uncaught exception handler only for current thread
            Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                @Override
                public void uncaughtException(Thread thread, Throwable thrown) {
                    listener.handleError("Uncaught exception thrown in "+thread.toString(), thrown);
                    if (needClose.get()) {
                        // listener.handleError() has requested the
                        // context to close. Satisfy request.
                        deinitInThread();
                    }
                }
            });
        }

        // For canvas, this will create a pbuffer,
        // allowing us to query information.
        // When the canvas context becomes available, it will
        // be replaced seamlessly.
        createContext(settings);
        printContextInitInfo();

        created.set(true);
        super.internalCreate();
    } catch (Exception ex) {
        try {
            if (Display.isCreated()) {
                Display.destroy();
            }
        } catch (Exception ex2){
            logger.log(Level.WARNING, null, ex2);
        }

        listener.handleError("Failed to create display", ex);
        createdLock.notifyAll(); // Release the lock, so start(true) doesn't deadlock.
        return false; // if we failed to create display, do not continue
    }

    listener.initialize();
    return true;
}
 
Example #25
Source File: TestMaterialCompare.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void main(String[] args) {
    AssetManager assetManager = JmeSystem.newAssetManager(
            TestMaterialCompare.class.getResource("/com/jme3/asset/Desktop.cfg"));
    
    // Cloned materials
    Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat1.setName("mat1");
    mat1.setColor("Color", ColorRGBA.Blue);

    Material mat2 = mat1.clone();
    mat2.setName("mat2");
    testEquality(mat1, mat2, true);

    // Cloned material with different render states
    Material mat3 = mat1.clone();
    mat3.setName("mat3");
    mat3.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);
    testEquality(mat1, mat3, false);

    // Two separately loaded materials
    Material mat4 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat4.setName("mat4");
    Material mat5 = assetManager.loadMaterial("Models/Sign Post/Sign Post.j3m");
    mat5.setName("mat5");
    testEquality(mat4, mat5, true);
    
    // Comparing same textures
    TextureKey originalKey = (TextureKey) mat4.getTextureParam("DiffuseMap").getTextureValue().getKey();
    TextureKey tex1key = new TextureKey("Models/Sign Post/Sign Post.jpg", false);
    tex1key.setGenerateMips(true);
    
    // Texture keys from the original and the loaded texture
    // must be identical, otherwise the resultant textures not identical
    // and thus materials are not identical!
    if (!originalKey.equals(tex1key)){
        System.out.println("TEXTURE KEYS ARE NOT EQUAL");
    }
    
    Texture tex1 = assetManager.loadTexture(tex1key);
    mat4.setTexture("DiffuseMap", tex1);
    testEquality(mat4, mat5, true);
    
    // Change some stuff on the texture and compare, materials no longer equal
    tex1.setWrap(Texture.WrapMode.MirroredRepeat);
    testEquality(mat4, mat5, false);
    
    // Comparing different textures
    Texture tex2 = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat4.setTexture("DiffuseMap", tex2);
    testEquality(mat4, mat5, false);

    // Two materials created the same way
    Material mat6 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat6.setName("mat6");
    mat6.setColor("Color", ColorRGBA.Blue);
    testEquality(mat1, mat6, true);

    // Changing a material param
    mat6.setColor("Color", ColorRGBA.Green);
    testEquality(mat1, mat6, false);
}
 
Example #26
Source File: TestManyLocators.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void main(String[] args){
    AssetManager am = JmeSystem.newAssetManager();

    am.registerLocator("http://wiki.jmonkeyengine.org/jme3/beginner",
                       UrlLocator.class);

    am.registerLocator("town.zip", ZipLocator.class);
    am.registerLocator(
                "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/wildhouse.zip", 
                HttpZipLocator.class);       
    
    am.registerLocator("/", ClasspathLocator.class);
    
    

    // Try loading from Core-Data source package
    AssetInfo a = am.locateAsset(new AssetKey<Object>("Interface/Fonts/Default.fnt"));

    // Try loading from town scene zip file
    AssetInfo b = am.locateAsset(new ModelKey("casaamarela.jpg"));

    // Try loading from wildhouse online scene zip file
    AssetInfo c = am.locateAsset(new ModelKey("glasstile2.png"));

    // Try loading directly from HTTP
    AssetInfo d = am.locateAsset(new TextureKey("beginner-physics.png"));

    if (a == null)
        System.out.println("Failed to load from classpath");
    else
        System.out.println("Found classpath font: " + a.toString());

    if (b == null)
        System.out.println("Failed to load from town.zip file");
    else
        System.out.println("Found zip image: " + b.toString());

    if (c == null)
        System.out.println("Failed to load from wildhouse.zip on googleapis.com");
    else
        System.out.println("Found online zip image: " + c.toString());

    if (d == null)
        System.out.println("Failed to load from HTTP");
    else
        System.out.println("Found HTTP showcase image: " + d.toString());
}
 
Example #27
Source File: TestCustomLoader.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void main(String[] args){
    AssetManager assetManager = JmeSystem.newAssetManager();
    assetManager.registerLocator("/", ClasspathLocator.class);
    assetManager.registerLoader(TextLoader.class, "fnt");
    System.out.println(assetManager.loadAsset("Interface/Fonts/Console.fnt"));
}
 
Example #28
Source File: LwjglCanvas.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * This is called:
 * 1) When the context thread ends
 * 2) Any time the canvas becomes non-displayable
 */
protected void destroyContext(){
    try {
        // invalidate the state so renderer can resume operation
        if (!USE_SHARED_CONTEXT){
            renderer.cleanup();
        }
        
        if (Display.isCreated()){
            /* FIXES:
             * org.lwjgl.LWJGLException: X Error
             * BadWindow (invalid Window parameter) request_code: 2 minor_code: 0
             * 
             * Destroying keyboard early prevents the error above, triggered
             * by destroying keyboard in by Display.destroy() or Display.setParent(null).
             * Therefore Keyboard.destroy() should precede any of these calls.
             */
            if (Keyboard.isCreated()){
                // Should only happen if called in 
                // LwjglAbstractDisplay.deinitInThread().
                Keyboard.destroy();
            }

            //try {
                // NOTE: On Windows XP, not calling setParent(null)
                // freezes the application.
                // On Mac it freezes the application.
                // On Linux it fixes a crash with X Window System.
                if (JmeSystem.getPlatform() == Platform.Windows32
                 || JmeSystem.getPlatform() == Platform.Windows64){
                    //Display.setParent(null);
                }
            //} catch (LWJGLException ex) {
            //    logger.log(Level.SEVERE, "Encountered exception when setting parent to null", ex);
            //}

            Display.destroy();
        }
        
        // The canvas is no longer visible,
        // but the context thread is still running.
        if (!needClose.get()){
            // MUST make sure there's still a context current here ..
            // Display is dead, make pbuffer available to the system
            makePbufferAvailable();
            
            renderer.invalidateState();
        }else{
            // The context thread is no longer running.
            // Destroy pbuffer.
            destroyPbuffer();
        }
    } catch (LWJGLException ex) {
        listener.handleError("Failed make pbuffer available", ex);
    }
}
 
Example #29
Source File: AndroidLocator.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public AndroidLocator()
{
    resources = JmeSystem.getResources();
    androidManager = resources.getAssets();
}
 
Example #30
Source File: IosHarness.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public IosHarness(long appDelegate) {
    super(appDelegate);
    JmeSystem.setSystemDelegate(new JmeIosSystem());
}