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);
    }
  }
  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;
  }
  /**
   * 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) {
    }
  }
Beispiel #5
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();
  }
Beispiel #6
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);
   }
 }
Beispiel #7
0
  /**
   * @param args ...
   * @throws Exception ...
   */
  public static void main(final String[] args) throws Exception {
    logger.info("Miner client started");
    try {

      // initialize task system so we can start up in parallel tasks
      Thread.currentThread().setName("Startup (later OpenGL)");
      TaskSystem.initialize();

      // parse command-line options
      logger.trace("parsing command line options...");
      boolean fullscreen = false;
      for (final String arg : args) {
        if (arg.equals("-fs")) {
          fullscreen = true;
        } else if (arg.equals("-6")) {
          screenWidth = 640;
          screenHeight = 480;
        } else if (arg.equals("-8")) {
          screenWidth = 800;
          screenHeight = 600;
        } else if (arg.equals("-1")) {
          screenWidth = 1024;
          screenHeight = 768;
        } else if (arg.equals("-12")) {
          screenWidth = 1280;
          screenHeight = 720;
        } else if (arg.equals("-16")) {
          screenWidth = 1680;
          screenHeight = 1050;
        }
      }
      logger.trace("command line options parsed");

      // create a worker loop -- we need to access this in closures
      logger.trace("initializing OpenGL worker scheme...");
      SimpleWorkerScheme.initialize();
      logger.trace("OpenGL worker scheme initialized");

      // prepare native libraries
      logger.trace("preparing native libraries...");
      LwjglNativeLibraryHelper.prepareNativeLibraries();
      logger.trace("native libraries prepared");

      // configure the display
      logger.trace("finding optimal display mode...");
      DisplayMode bestMode = null;
      int bestModeFrequency = -1;
      for (DisplayMode mode : Display.getAvailableDisplayModes()) {
        if (mode.getWidth() == screenWidth
            && mode.getHeight() == screenHeight
            && (mode.isFullscreenCapable() || !fullscreen)) {
          if (mode.getFrequency() > bestModeFrequency) {
            bestMode = mode;
            bestModeFrequency = mode.getFrequency();
          }
        }
      }
      if (bestMode == null) {
        bestMode = new DisplayMode(screenWidth, screenHeight);
      }
      logger.trace("setting intended display mode...");
      Display.setDisplayMode(bestMode);
      if (fullscreen) {
        Display.setFullscreen(true);
      }
      logger.trace("switching display mode...");
      Display.create(new PixelFormat(0, 24, 0));
      logger.trace("display initialized");

      // initialize LWJGL
      logger.trace("preparing mouse...");
      Mouse.create();
      Mouse.poll();
      logger.trace("mouse prepared");

      // build the frame loop
      OsmWorld world = new OsmLoader().loadWorld(new File("resource/map.osm"));
      OsmViewer viewer = new OsmViewer(world);
      HandlerList handlerList = new HandlerList();
      handlerList.add(viewer);
      handlerList.add(new ExitHandler(true, Keyboard.KEY_ESCAPE));
      frameLoop = new FrameLoop(SimpleWorkerScheme.getGlWorkerLoop());
      frameLoop.getRootHandler().setWrappedHandler(handlerList);

      // TODO remove, used for development
      logger.info("auto-login...");
      logger.info("auto-login successful");

      // run the game logic in a different thread, then run the OpenGL worker in the main thread
      new Thread("Application") {
        @Override
        public void run() {
          frameLoop.executeLoop(10);
          SimpleWorkerScheme.requestStop();
        };
      }.start();
      logger.debug("startup thread becoming the OpenGL thread now");
      Thread.currentThread().setName("OpenGL");
      SimpleWorkerScheme.workAndWait();

      // clean up
      Display.destroy();

    } catch (final Exception e) {
      e.printStackTrace();
    }
    System.exit(0);
  }