private static void setDisplayModeAndFullscreenInternal(boolean fullscreen, DisplayMode mode)
     throws LWJGLException {
   synchronized (GlobalLock.lock) {
     if (mode == null) throw new NullPointerException("mode must be non-null");
     DisplayMode old_mode = current_mode;
     current_mode = mode;
     boolean was_fullscreen = isFullscreen();
     Display.fullscreen = fullscreen;
     if (was_fullscreen != isFullscreen() || !mode.equals(old_mode)) {
       if (!isCreated()) return;
       destroyWindow();
       try {
         if (isFullscreen()) {
           switchDisplayMode();
         } else {
           display_impl.resetDisplayMode();
         }
         createWindow();
         makeCurrentAndSetSwapInterval();
       } catch (LWJGLException e) {
         drawable.destroy();
         display_impl.resetDisplayMode();
         throw e;
       }
     }
   }
 }
 /**
  * Set the current display mode. If no OpenGL context has been created, the given mode will apply
  * to the context when create() is called, and no immediate mode switching will happen. If there
  * is a context already, it will be resized according to the given mode. If the context is also a
  * fullscreen context, the mode will also be switched immediately. The native cursor position is
  * also reset.
  *
  * @param mode The new display mode to set
  * @throws LWJGLException if the display mode could not be set
  */
 public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
   synchronized (GlobalLock.lock) {
     if (mode == null) throw new NullPointerException("mode must be non-null");
     boolean was_fullscreen = isFullscreen();
     current_mode = mode;
     if (isCreated()) {
       destroyWindow();
       // If mode is not fullscreen capable, make sure we are in windowed mode
       try {
         if (was_fullscreen && !isFullscreen()) display_impl.resetDisplayMode();
         else if (isFullscreen()) switchDisplayMode();
         createWindow();
         makeCurrentAndSetSwapInterval();
       } catch (LWJGLException e) {
         drawable.destroy();
         display_impl.resetDisplayMode();
         throw e;
       }
     }
   }
 }
 /**
  * Set the parent of the Display. If parent is null, the Display will appear as a top level
  * window. If parent is not null, the Display is made a child of the parent. A parent's
  * isDisplayable() must be true when setParent() is called and remain true until setParent() is
  * called again with null or a different parent. This generally means that the parent component
  * must remain added to it's parent container.
  *
  * <p>It is not advisable to call this method from an AWT thread, since the context will be made
  * current on the thread and it is difficult to predict which AWT thread will process any given
  * AWT event.
  *
  * <p>While the Display is in fullscreen mode, the current parent will be ignored. Additionally,
  * when a non null parent is specified, the Dispaly will inherit the size of the parent,
  * disregarding the currently set display mode.
  *
  * <p>
  */
 public static void setParent(Canvas parent) throws LWJGLException {
   synchronized (GlobalLock.lock) {
     if (Display.parent != parent) {
       Display.parent = parent;
       if (!isCreated()) return;
       destroyWindow();
       try {
         if (isFullscreen()) {
           switchDisplayMode();
         } else {
           display_impl.resetDisplayMode();
         }
         createWindow();
         makeCurrentAndSetSwapInterval();
       } catch (LWJGLException e) {
         drawable.destroy();
         display_impl.resetDisplayMode();
         throw e;
       }
     }
   }
 }
  /**
   * Create the OpenGL ES context with the given minimum parameters. If isFullscreen() is true or if
   * windowed context are not supported on the platform, the display mode will be switched to the
   * mode returned by getDisplayMode(), and a fullscreen context will be created. If isFullscreen()
   * is false, a windowed context will be created with the dimensions given in the mode returned by
   * getDisplayMode(). If a context can't be created with the given parameters, a LWJGLException
   * will be thrown.
   *
   * <p>
   *
   * <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with
   * GL coordinates.
   *
   * @param pixel_format Describes the minimum specifications the context must fulfill. Must be an
   *     instance of org.lwjgl.opengles.PixelFormat.
   * @param shared_drawable The Drawable to share context with. (optional, may be null)
   * @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
   * @throws LWJGLException
   */
  public static void create(
      PixelFormatLWJGL pixel_format,
      Drawable shared_drawable,
      org.lwjgl.opengles.ContextAttribs attribs)
      throws LWJGLException {
    synchronized (GlobalLock.lock) {
      if (isCreated())
        throw new IllegalStateException(
            "Only one LWJGL context may be instantiated at any one time.");
      if (pixel_format == null) throw new NullPointerException("pixel_format cannot be null");
      removeShutdownHook();
      registerShutdownHook();
      if (isFullscreen()) switchDisplayMode();

      final DrawableGLES drawable =
          new DrawableGLES() {

            public void setPixelFormat(final PixelFormatLWJGL pf, final ContextAttribs attribs)
                throws LWJGLException {
              throw new UnsupportedOperationException();
            }

            public void destroy() {
              synchronized (GlobalLock.lock) {
                if (!isCreated()) return;

                releaseDrawable();
                super.destroy();
                destroyWindow();
                x = y = -1;
                cached_icons = null;
                reset();
                removeShutdownHook();
              }
            }
          };
      Display.drawable = drawable;

      try {
        drawable.setPixelFormat(pixel_format);
        try {
          createWindow();
          try {
            drawable.createContext(attribs, shared_drawable);
            try {
              makeCurrentAndSetSwapInterval();
              initContext();
            } catch (LWJGLException e) {
              drawable.destroy();
              throw e;
            }
          } catch (LWJGLException e) {
            destroyWindow();
            throw e;
          }
        } catch (LWJGLException e) {
          drawable.destroy();
          throw e;
        }
      } catch (LWJGLException e) {
        display_impl.resetDisplayMode();
        throw e;
      }
    }
  }
  /**
   * Create the OpenGL context with the given minimum parameters. If isFullscreen() is true or if
   * windowed context are not supported on the platform, the display mode will be switched to the
   * mode returned by getDisplayMode(), and a fullscreen context will be created. If isFullscreen()
   * is false, a windowed context will be created with the dimensions given in the mode returned by
   * getDisplayMode(). If a context can't be created with the given parameters, a LWJGLException
   * will be thrown.
   *
   * <p>
   *
   * <p>The window created will be set up in orthographic 2D projection, with 1:1 pixel ratio with
   * GL coordinates.
   *
   * @param pixel_format Describes the minimum specifications the context must fulfill.
   * @param shared_drawable The Drawable to share context with. (optional, may be null)
   * @param attribs The ContextAttribs to use when creating the context. (optional, may be null)
   * @throws LWJGLException
   */
  public static void create(
      PixelFormat pixel_format, Drawable shared_drawable, ContextAttribs attribs)
      throws LWJGLException {
    synchronized (GlobalLock.lock) {
      if (isCreated())
        throw new IllegalStateException(
            "Only one LWJGL context may be instantiated at any one time.");
      if (pixel_format == null) throw new NullPointerException("pixel_format cannot be null");
      removeShutdownHook();
      registerShutdownHook();
      if (isFullscreen()) switchDisplayMode();

      final DrawableGL drawable =
          new DrawableGL() {
            public void destroy() {
              synchronized (GlobalLock.lock) {
                if (!isCreated()) return;

                releaseDrawable();
                super.destroy();
                destroyWindow();
                x = y = -1;
                cached_icons = null;
                reset();
                removeShutdownHook();
              }
            }
          };
      Display.drawable = drawable;

      try {
        drawable.setPixelFormat(pixel_format, attribs);
        try {
          createWindow();
          try {
            drawable.context =
                new ContextGL(
                    drawable.peer_info,
                    attribs,
                    shared_drawable != null ? ((DrawableGL) shared_drawable).getContext() : null);
            try {
              makeCurrentAndSetSwapInterval();
              initContext();
            } catch (LWJGLException e) {
              drawable.destroy();
              throw e;
            }
          } catch (LWJGLException e) {
            destroyWindow();
            throw e;
          }
        } catch (LWJGLException e) {
          drawable.destroy();
          throw e;
        }
      } catch (LWJGLException e) {
        display_impl.resetDisplayMode();
        throw e;
      }
    }
  }