Ejemplo n.º 1
1
 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;
       }
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * Swap the display buffers. This method is called from update(), and should normally not be
   * called by the application.
   *
   * @throws OpenGLException if an OpenGL error has occured since the last call to glGetError()
   */
  public static void swapBuffers() throws LWJGLException {
    synchronized (GlobalLock.lock) {
      if (!isCreated()) throw new IllegalStateException("Display not created");

      if (LWJGLUtil.DEBUG) drawable.checkGLError();
      drawable.swapBuffers();
    }
  }
Ejemplo n.º 3
0
 private static void makeCurrentAndSetSwapInterval() throws LWJGLException {
   makeCurrent();
   try {
     drawable.checkGLError();
   } catch (OpenGLException e) {
     LWJGLUtil.log("OpenGL error during context creation: " + e.getMessage());
   }
   setSwapInterval(swap_interval);
 }
Ejemplo n.º 4
0
 private static void releaseDrawable() {
   try {
     Context context = drawable.getContext();
     if (context != null && context.isCurrent()) {
       context.releaseCurrent();
       context.releaseDrawable();
     }
   } catch (LWJGLException e) {
     LWJGLUtil.log("Exception occurred while trying to release context: " + e);
   }
 }
Ejemplo n.º 5
0
 /**
  * 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;
       }
     }
   }
 }
Ejemplo n.º 6
0
 /**
  * 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;
       }
     }
   }
 }
Ejemplo n.º 7
0
 /**
  * Make the Display the current rendering context for GL calls.
  *
  * @throws LWJGLException If the context could not be made current
  */
 public static void makeCurrent() throws LWJGLException {
   drawable.makeCurrent();
 }
Ejemplo n.º 8
0
 /** Returns true if the Display's context is current in the current thread. */
 public static boolean isCurrent() throws LWJGLException {
   return drawable.isCurrent();
 }
Ejemplo n.º 9
0
 /**
  * Release the Display context.
  *
  * @throws LWJGLException If the context could not be released
  */
 public static void releaseContext() throws LWJGLException {
   drawable.releaseContext();
 }
Ejemplo n.º 10
0
 /**
  * Set the buffer swap interval. This call is a best-attempt at changing the monitor swap
  * interval, which is the minimum periodicity of color buffer swaps, measured in video frame
  * periods, and is not guaranteed to be successful.
  *
  * <p>A video frame period is the time required to display a full frame of video data.
  *
  * @param value The swap interval in frames, 0 to disable
  */
 public static void setSwapInterval(int value) {
   synchronized (GlobalLock.lock) {
     swap_interval = value;
     if (isCreated()) drawable.setSwapInterval(swap_interval);
   }
 }
Ejemplo n.º 11
0
 /**
  * Destroy the Display. After this call, there will be no current GL rendering context, regardless
  * of whether the Display was the current rendering context.
  */
 public static void destroy() {
   if (isCreated()) {
     drawable.destroy();
   }
 }
Ejemplo n.º 12
0
 private static void initContext() {
   drawable.initContext(r, g, b);
   update();
 }
Ejemplo n.º 13
0
  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;
    }
  }