Ejemplo n.º 1
0
  public static DisplayMode[] getFullscreenDisplayModes() {
    try {
      DisplayMode[] var0 = Display.getAvailableDisplayModes();
      ArrayList var1 = new ArrayList();

      for (int var2 = 0; var2 < var0.length; ++var2) {
        DisplayMode var3 = var0[var2];

        if (desktopDisplayMode == null
            || var3.getBitsPerPixel() == desktopDisplayMode.getBitsPerPixel()
                && var3.getFrequency() == desktopDisplayMode.getFrequency()) {
          var1.add(var3);
        }
      }

      DisplayMode[] var5 =
          (DisplayMode[]) ((DisplayMode[]) var1.toArray(new DisplayMode[var1.size()]));
      Config$1 var6 = new Config$1();
      Arrays.sort(var5, var6);
      return var5;
    } catch (Exception var4) {
      var4.printStackTrace();
      return new DisplayMode[] {desktopDisplayMode};
    }
  }
  /**
   * Set the display mode to be used
   *
   * @param width The width of the display required
   * @param height The height of the display required
   * @param fullscreen True if we want fullscreen mode
   */
  public void setDisplayMode(int width, int height, boolean fullscreen) {

    // return if requested DisplayMode is already set
    if ((Display.getDisplayMode().getWidth() == width)
        && (Display.getDisplayMode().getHeight() == height)
        && (Display.isFullscreen() == fullscreen)) {
      return;
    }

    try {
      DisplayMode targetDisplayMode = null;

      if (fullscreen) {
        DisplayMode[] modes = Display.getAvailableDisplayModes();
        int freq = 0;

        for (int i = 0; i < modes.length; i++) {
          DisplayMode current = modes[i];

          if ((current.getWidth() == width) && (current.getHeight() == height)) {
            if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) {
              if ((targetDisplayMode == null)
                  || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) {
                targetDisplayMode = current;
                freq = targetDisplayMode.getFrequency();
              }
            }

            // if we've found a match for bpp and frequence against the
            // original display mode then it's probably best to go for this one
            // since it's most likely compatible with the monitor
            if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel())
                && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) {
              targetDisplayMode = current;
              break;
            }
          }
        }
      } else {
        targetDisplayMode = new DisplayMode(width, height);
      }

      if (targetDisplayMode == null) {
        System.out.println(
            "Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen);
        return;
      }

      Display.setDisplayMode(targetDisplayMode);
      Display.setFullscreen(fullscreen);

    } catch (LWJGLException e) {
      System.out.println(
          "Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e);
    }
  }
Ejemplo n.º 3
0
  public static DisplayMode getDisplayMode(Dimension var0) throws LWJGLException {
    DisplayMode[] var1 = Display.getAvailableDisplayModes();

    for (int var2 = 0; var2 < var1.length; ++var2) {
      DisplayMode var3 = var1[var2];

      if (var3.getWidth() == var0.width
          && var3.getHeight() == var0.height
          && (desktopDisplayMode == null
              || var3.getBitsPerPixel() == desktopDisplayMode.getBitsPerPixel()
                  && var3.getFrequency() == desktopDisplayMode.getFrequency())) {
        return var3;
      }
    }

    return desktopDisplayMode;
  }
Ejemplo n.º 4
0
  public static void setWindowResolution(int width, int height) {
    Globals.windowWidth = width;
    Globals.windowHeight = height;
    Globals.aspectRatio = (float) Globals.windowWidth / (float) Globals.windowHeight;
    Globals.windowMatrix.set(
        1 / Globals.aspectRatio,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f);

    // for(IWindowChangeListener lis : Globals.windowChangeListener)
    // {
    //	lis.onWindowResolutionChange(Globals.windowWidth, Globals.windowHeight);
    // }

    try {
      DisplayMode[] modes = Display.getAvailableDisplayModes();

      DisplayMode finalMode = new DisplayMode(Globals.getWindowWidth(), Globals.getWindowHeight());

      for (int i = 0; i < modes.length; i++) {
        DisplayMode current = modes[i];
        if (current.getWidth() == Globals.getWindowWidth()
            && current.getHeight() == Globals.getWindowHeight()
            && current.getBitsPerPixel() == 32
            && current.getFrequency() == 60) finalMode = current;
      }

      Display.setDisplayMode(finalMode);

      if (!Display.isCreated()) {
        PixelFormat pixelFormat = new PixelFormat();
        ContextAttribs contextAtrributes =
            new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true);
        Display.create(pixelFormat, contextAtrributes);
      }

      GL11.glViewport(0, 0, Globals.getWindowWidth(), Globals.getWindowHeight());
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(-1);
    }
    Display.update();
  }
Ejemplo n.º 5
0
 public void setDisplayMode(int width, int height, boolean fullscreen) {
   if ((Display.getDisplayMode().getWidth() == width)
       && (Display.getDisplayMode().getHeight() == height)
       && (Display.isFullscreen() == fullscreen)) {
     return;
   }
   try {
     DisplayMode targetDisplayMode = null;
     if (fullscreen) {
       DisplayMode[] modes = Display.getAvailableDisplayModes();
       int freq = 0;
       for (int i = 0; i < modes.length; i++) {
         DisplayMode current = modes[i];
         if ((current.getWidth() == width) && (current.getHeight() == height)) {
           if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) {
             if ((targetDisplayMode == null)
                 || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) {
               targetDisplayMode = current;
               freq = targetDisplayMode.getFrequency();
             }
           }
           if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel())
               && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) {
             targetDisplayMode = current;
             break;
           }
         }
       }
     } else targetDisplayMode = new DisplayMode(width, height);
     if (targetDisplayMode == null) {
       System.out.println(
           "Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen);
       return;
     }
     Display.setDisplayMode(targetDisplayMode);
     Display.setFullscreen(fullscreen);
   } catch (LWJGLException e) {
     System.out.println(
         "Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e);
   }
 }
Ejemplo n.º 6
0
  private DisplayMode findDisplayMode(int width, int height, int bpp) throws LWJGLException {
    DisplayMode[] modes = Display.getAvailableDisplayModes();
    DisplayMode mode = null;

    for (DisplayMode dm : modes) {
      if ((dm.getBitsPerPixel() == bpp) || (mode == null)) {
        if ((dm.getWidth() == width) && (dm.getHeight() == height)) {
          mode = dm;
        }
      }
    }

    return mode;
  }
  /**
   * Get all LWJGL DisplayModes into the DropDown
   *
   * @param screen
   */
  private void fillResolutionDropDown(final Screen screen) {
    try {
      DisplayMode currentMode = Display.getDisplayMode();
      List<DisplayMode> sorted = new ArrayList<DisplayMode>();

      DisplayMode[] modes = Display.getAvailableDisplayModes();
      for (int i = 0; i < modes.length; i++) {
        DisplayMode mode = modes[i];
        if (mode.getBitsPerPixel() == 32 && mode.getFrequency() == currentMode.getFrequency()) {
          // since Nifty does not yet support automatically rescaling of the GUI and since this
          // example/demo was designed for 1024x768 pixel we can't allow resolutions below this
          // size.
          if (mode.getWidth() >= 1024 && mode.getHeight() >= 768) {
            sorted.add(mode);
          }
        }
      }

      Collections.sort(
          sorted,
          new Comparator<DisplayMode>() {
            @Override
            public int compare(DisplayMode o1, DisplayMode o2) {
              int widthCompare =
                  Integer.valueOf(o1.getWidth()).compareTo(Integer.valueOf(o2.getWidth()));
              if (widthCompare != 0) {
                return widthCompare;
              }
              int heightCompare =
                  Integer.valueOf(o1.getHeight()).compareTo(Integer.valueOf(o2.getHeight()));
              if (heightCompare != 0) {
                return heightCompare;
              }
              return o1.toString().compareTo(o2.toString());
            }
          });

      DropDown dropDown = screen.findNiftyControl("resolutions", DropDown.class);
      for (DisplayMode mode : sorted) {
        dropDown.addItem(mode);
      }
    } catch (Exception e) {
    }
  }
Ejemplo n.º 8
0
  public void run(Map<String, String> parameters) {
    DisplayManager.create();
    DisplayManager displayManager = DisplayManager.getInstance();
    displayManager.setWindowTitle(TITLE);
    ObjectObserver objectObserver = new ObjectObserverMoteJ();
    WindowManager windowManager = null;

    try {
      for (DisplayMode mode : displayManager.getAvailableDisplayModes()) {
        log.info(mode.getWidth() + "x" + mode.getHeight() + ":" + mode.getBitsPerPixel());
      }
      displayMode = displayManager.getDisplayMode(800, 600, 32);
      displayManager.createDisplay(displayMode);
      Keyboard.create();

      objectObserver.initialize(parameters);

      WindowManager.create(displayManager, objectObserver);
      windowManager = WindowManager.getInstance();
      windowManager.getWindowManagerCalibrator().addWindowManagerCalibratorListener(this);

      FrameMeter frameMeter = new FrameMeter();
      calibrationRequested = true;
      isCalibrated = false;
      isRunning = true;
      while (isRunning) {
        if (Display.isCloseRequested()) {
          break;
        }

        while (Keyboard.next()) {
          if (Keyboard.getEventKey() == Keyboard.KEY_F) {
            if (Keyboard.getEventKeyState()) {
              displayManager.setFullScreen(!displayManager.isFullScreen());
            }
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_ESCAPE) {
            isRunning = false;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_C) {
            calibrationRequested = true;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_UP) {
            ballSpeed += 0.1f;
          }
          if (Keyboard.getEventKey() == Keyboard.KEY_DOWN) {
            ballSpeed -= 0.1f;
          }
        }

        if (calibrationRequested) {
          windowManager.calibrate();
          calibrationRequested = false;
          isCalibrated = false;
        } else if (isCalibrated) {
          windowManager.setCursorCollection(new CursorCollectionDefault());

          log.info("Loading images...");
          loadImages();
          isCalibrated = false;

          gameState = GameState.Ready;
        }

        if (frameMeter.update()) {
          displayManager.setWindowTitle(TITLE + " - " + frameMeter.getFps() + " fps");
        }

        // game state
        if (gameState != null) {
          if (gameState.equals(GameState.Ready)) {
            onGameStateReady();
          } else if (gameState.equals(GameState.Start)) {
            onGameStateStart();
          } else if (gameState.equals(GameState.Playing)) {
            onGameStatePlaying();
          } else if (gameState.equals(GameState.End)) {
            onGameStateEnd();
          }
        }

        windowManager.update();
        Thread.sleep(30);
      }
    } catch (Exception exception) {
      exception.printStackTrace();
    } finally {
      try {
        if (windowManager != null) {
          windowManager.destroy();
        }
        Keyboard.destroy();
        displayManager.destroy();
      } catch (Exception exception) {
        exception.printStackTrace();
      }
    }
  }