@Override
    protected void createContext(AppSettings settings) throws LWJGLException {
        DisplayMode displayMode;
        if (settings.getWidth() <= 0 || settings.getHeight() <= 0) {
            displayMode = Display.getDesktopDisplayMode();
            settings.setResolution(displayMode.getWidth(), displayMode.getHeight());
        } else if (settings.isFullscreen()) {
            displayMode =
                getFullscreenDisplayMode(
                    settings.getWidth(),
                    settings.getHeight(),
                    settings.getBitsPerPixel(),
                    settings.getFrequency()
                );
            if (displayMode == null) {
                // Fall back to whatever mode is available at the specified width & height
                displayMode = getFullscreenDisplayMode(settings.getWidth(), settings.getHeight(), -1, -1);
                if (displayMode == null) {
                    throw new RuntimeException("Unable to find fullscreen display mode matching settings");
                } else {
                    logger.log(
                        Level.WARNING,
                        "Unable to find fullscreen display mode matching settings, falling back to: {0}",
                        displayMode
                    );
                }
            }
        } else {
            displayMode = new DisplayMode(settings.getWidth(), settings.getHeight());
        }

        int samples = getNumSamplesToUse();
        PixelFormat pf = new PixelFormat(
            settings.getBitsPerPixel(),
            settings.getAlphaBits(),
            settings.getDepthBits(),
            settings.getStencilBits(),
            samples,
            0,
            0,
            0,
            settings.useStereo3D()
        );

        frameRate = settings.getFrameRate();
        allowSwapBuffers = settings.isSwapBuffers();
        logger.log(Level.FINE, "Selected display mode: {0}", displayMode);

        boolean pixelFormatChanged = false;
        if (
            created.get() &&
            (pixelFormat.getBitsPerPixel() != pf.getBitsPerPixel() ||
                pixelFormat.getAlphaBits() != pf.getAlphaBits() ||
                pixelFormat.getDepthBits() != pf.getDepthBits() ||
                pixelFormat.getStencilBits() != pf.getStencilBits() ||
                pixelFormat.getSamples() != pf.getSamples())
        ) {
            renderer.resetGLObjects();
            Display.destroy();
            pixelFormatChanged = true;
        }
        pixelFormat = pf;

        Display.setTitle(settings.getTitle());
        Display.setResizable(settings.isResizable());

        if (settings.isFullscreen()) {
            Display.setDisplayModeAndFullscreen(displayMode);
        } else {
            Display.setFullscreen(false);
            Display.setDisplayMode(displayMode);
        }

        if (settings.getIcons() != null) {
            Display.setIcon(imagesToByteBuffers(settings.getIcons()));
        }

        Display.setVSyncEnabled(settings.isVSync());

        if (created.get() && !pixelFormatChanged) {
            renderer.resetGLObjects();
            Display.releaseContext();
            Display.makeCurrent();
            Display.update();
        }

        if (!created.get() || pixelFormatChanged) {
            ContextAttribs attr = createContextAttribs();
            if (attr != null) {
                Display.create(pixelFormat, attr);
            } else {
                Display.create(pixelFormat);
            }
            renderable.set(true);

            if (
                pixelFormatChanged &&
                pixelFormat.getSamples() > 1 &&
                GLContext.getCapabilities().GL_ARB_multisample
            ) {
                GL11.glEnable(ARBMultisample.GL_MULTISAMPLE_ARB);
            }
        }

        if (settings.isOpenCLSupport()) {
            initOpenCL();
        }
    }
@param width The required display width
@param height The required display height
@param bpp The required bits per pixel. If -1 is passed it will return
          whatever bpp is found
@param freq The required frequency, if -1 is passed it will return
            whatever frequency is found
@return The {@link DisplayMode} matches with specified settings or
        return null if no matching display mode is found
jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java