コード例 #1
0
  /**
   * 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;
      }
    }
  }
コード例 #2
0
ファイル: WindowsDisplay.java プロジェクト: ravenocean/lwjgl
  public void createWindow(DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y)
      throws LWJGLException {
    close_requested = false;
    is_dirty = false;
    isMinimized = false;
    isFocused = false;
    redoMakeContextCurrent = false;
    maximized = false;
    this.parent = parent;
    hasParent = parent != null;
    parent_hwnd = parent != null ? getHwnd(parent) : 0;
    this.hwnd =
        nCreateWindow(
            x,
            y,
            mode.getWidth(),
            mode.getHeight(),
            Display.isFullscreen() || isUndecorated(),
            parent != null,
            parent_hwnd);
    this.resizable = false;
    if (hwnd == 0) {
      throw new LWJGLException("Failed to create window");
    }
    this.hdc = getDC(hwnd);
    if (hdc == 0) {
      nDestroyWindow(hwnd);
      throw new LWJGLException("Failed to get dc");
    }

    try {
      if (drawable instanceof DrawableGL) {
        int format =
            WindowsPeerInfo.choosePixelFormat(
                getHdc(),
                0,
                0,
                (PixelFormat) drawable.getPixelFormat(),
                null,
                true,
                true,
                false,
                true);
        WindowsPeerInfo.setPixelFormat(getHdc(), format);
      } else {
        peer_info = new WindowsDisplayPeerInfo(true);
        ((DrawableGLES) drawable)
            .initialize(
                hwnd,
                hdc,
                EGL.EGL_WINDOW_BIT,
                (org.lwjgl.opengles.PixelFormat) drawable.getPixelFormat());
      }
      peer_info.initDC(getHwnd(), getHdc());
      showWindow(getHwnd(), SW_SHOWDEFAULT);

      updateWidthAndHeight();

      if (parent == null) {
        if (Display.isResizable()) {
          setResizable(true);
        }
        setForegroundWindow(getHwnd());
      } else {
        parent_focused = new AtomicBoolean(false);
        parent.addFocusListener(
            parent_focus_tracker =
                new FocusAdapter() {
                  public void focusGained(FocusEvent e) {
                    parent_focused.set(true);
                    clearAWTFocus();
                  }
                });
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                clearAWTFocus();
              }
            });
      }
      grabFocus();
    } catch (LWJGLException e) {
      nReleaseDC(hwnd, hdc);
      nDestroyWindow(hwnd);
      throw e;
    }
  }