示例#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};
    }
  }
示例#2
0
  // ***************************************************************************
  // initDisplay
  // ***************************************************************************
  private static void initDisplay(boolean fullscreen) {
    DisplayMode chosenMode = null;

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

      for (int i = 0; i < modes.length; i++) {
        if ((modes[i].getWidth() == targetWidth) && (modes[i].getHeight() == targetHeight)) {
          chosenMode = modes[i];
          break;
        }
      }
    } catch (LWJGLException e) {
      Sys.alert("Error", "Unable to determine display modes.");
      System.exit(0);
    }

    // at this point if we have no mode there was no appropriate, let the user know
    // and give up
    if (chosenMode == null) {
      Sys.alert("Error", "Unable to find appropriate display mode.");
      System.exit(0);
    }

    try {
      Display.setDisplayMode(chosenMode);
      Display.setFullscreen(fullscreen);
      Display.setTitle("OpenCraft");
      Display.create();

    } catch (LWJGLException e) {
      Sys.alert("Error", "Unable to create display.");
      System.exit(0);
    }
  }
  /**
   * 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);
    }
  }
示例#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();
  }
示例#5
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;
  }
示例#6
0
  @Override
  public boolean init(Engine engine) {
    Window window = engine.getGlobal(Window.class);
    try {
      DisplayMode[] modes = Display.getAvailableDisplayModes();
      DisplayMode chosen = modes[0];

      for (DisplayMode mode : modes) {
        if (mode.getWidth() == window.width
            && mode.getHeight() == window.height
            && mode.isFullscreenCapable()) {
          chosen = mode;
        }
        break;
      }

      chosen =
          (DisplayMode)
              JOptionPane.showInputDialog(
                  null,
                  "Display Options",
                  "Display Mode",
                  JOptionPane.QUESTION_MESSAGE,
                  null,
                  modes,
                  chosen);
      if (chosen == null) {
        return false;
      }
      Display.setDisplayMode(chosen);
      Display.setFullscreen(
          JOptionPane.showConfirmDialog(
                  null, "Fullscreen?", "Display Options", JOptionPane.YES_NO_OPTION)
              == JOptionPane.YES_OPTION);
      Display.setVSyncEnabled(true);
      Display.create();

      glClearColor(1, 1, 1, 1);
      glEnable(GL_DEPTH_TEST);
      glEnable(GL_CULL_FACE);
    } catch (LWJGLException ex) {
      System.err.println("Error creating display: " + ex.getMessage());
      return false;
    }

    return true;
  }
示例#7
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;
  }
  /**
   * 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) {
    }
  }
示例#9
0
  private void createDisplay() {
    try {
      // Get the current screen size
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      Dimension scrnsize = toolkit.getScreenSize();

      float myResolution = (float) scrnsize.width / scrnsize.height;
      float availableRes = 0;
      int compatibleResI = 0;
      float smallWidth = scrnsize.width;

      System.out.println(Display.getDisplayMode().isFullscreenCapable());
      DisplayMode[] d = Display.getAvailableDisplayModes();
      for (int i = 0; i < d.length; i++) {
        System.out.println(d[i]);
        availableRes = (float) d[i].getWidth() / d[i].getHeight();
        // check if this resolution is compatible and if smaller
        if (myResolution == availableRes && d[i].getWidth() >= smallWidth) {
          compatibleResI = i;
          smallWidth = d[i].getWidth();
        }
      }
      sM = d[compatibleResI];

      Display.setDisplayMode(sM);
      Constants.VIEW_HEIGHT = sM.getHeight();
      Constants.VIEW_WIDTH = sM.getWidth();
      Display.setFullscreen(fullScr);

      // set font scale depending on resolution (800 x 600 is base, dependant on height)
      Fonts.resolutionScale = (float) Constants.VIEW_HEIGHT / 600;

      Constants.DEFAULT_PLAYER_X = Constants.VIEW_WIDTH / 2;
      Constants.DEFAULT_PLAYER_Y = Constants.VIEW_HEIGHT / 2;

      //			Display.setDisplayMode(new DisplayMode(Constants.VIEW_WIDTH, Constants.VIEW_HEIGHT));
      Display.setTitle(Constants.GAME_NAME);
      Display.create();
      Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
  }
示例#10
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);
   }
 }
示例#11
0
文件: Vorxel.java 项目: Pitzik4/Geode
  public static void init(VorxelSettings set, Geode gamep) {
    world = new World();
    game = gamep;
    try {
      DisplayMode d[] = Display.getAvailableDisplayModes();
      DisplayMode displayMode = d[0];
      Display.setDisplayMode(displayMode);
      Display.create();

      Mouse.create();
      Keyboard.create();

      GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
      GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
      GL11.glClearDepth(1.0); // Depth Buffer Setup
      GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
      GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do

      GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
      GL11.glLoadIdentity(); // Reset The Projection Matrix
      // Calculate The Aspect Ratio Of The Window
      GLU.gluPerspective(
          45.0f, (float) displayMode.getWidth() / (float) displayMode.getHeight(), 0.1f, 100.0f);
      GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

      // Really Nice Perspective Calculations
      GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
      TextureHelper.init();
      Cube.dirt.texture = new VTex(4);
      Cube.grass.texture = Cube.dirt.texture;
      Cube.grass.toptexture = new VTex(1);
      Mouse.setGrabbed(true);
      world.createSpawn();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
  }
示例#12
0
 @Override
 public void init() {
   try {
     DisplayMode[] modes = Display.getAvailableDisplayModes();
     int closestindex = -1;
     for (int i = 0; i < modes.length; i++) {
       if (closestindex == -1) closestindex = 0;
       else if (getModeDist(modes[closestindex]) > getModeDist(modes[i])) closestindex = i;
     }
     Display.setDisplayMode(modes[closestindex]);
     Display.setTitle("Voxels " + Main.Version);
     Display.create();
     setVSyncEnabled(Main.isVSyncEnabled);
     org.lwjgl.input.Mouse.create();
     org.lwjgl.input.Keyboard.create();
     org.lwjgl.input.Keyboard.enableRepeatEvents(true);
     if (!AL.isCreated()) AL.create();
     this.mouse.init();
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#13
0
  /** Tests querying for modes */
  private void queryModesTest() throws LWJGLException {
    DisplayMode[] modes = null;

    System.out.println("==== Test query ====");
    System.out.println("Retrieving available displaymodes");
    modes = Display.getAvailableDisplayModes();

    // no modes check
    if (modes == null) {
      System.out.println("FATAL: unable to find any modes!");
      System.exit(-1);
    }

    // write some info
    System.out.println("Found " + modes.length + " modes");
    System.out.println("The first 5 are:");
    for (int i = 0; i < modes.length; i++) {
      System.out.println(modes[i]);
      if (i == 5) {
        break;
      }
    }
    System.out.println("---- Test query ----");
  }
示例#14
0
  /** Tests setting display modes */
  private void setDisplayModeTest() throws LWJGLException {
    DisplayMode mode = null;
    DisplayMode[] modes = null;

    System.out.println("==== Test setDisplayMode ====");
    System.out.println("Retrieving available displaymodes");
    modes = Display.getAvailableDisplayModes();

    // no modes check
    if (modes == null) {
      System.out.println("FATAL: unable to find any modes!");
      System.exit(-1);
    }

    // find a mode
    System.out.print("Looking for 640x480...");
    for (int i = 0; i < modes.length; i++) {
      if (modes[i].getWidth() == 640 && modes[i].getHeight() == 480) {
        mode = modes[i];
        System.out.println("found!");
        break;
      }
    }

    // no mode check
    if (mode == null) {
      System.out.println("error\nFATAL: Unable to find basic mode.");
      System.exit(-1);
    }

    // change to mode, and wait a bit
    System.out.print("Changing to mode...");
    try {
      Display.setDisplayMode(mode);
      Display.setFullscreen(true);
      Display.create();
    } catch (Exception e) {
      System.out.println("error\nFATAL: Error setting mode");
      System.exit(-1);
    }
    System.out.println("done");

    System.out.println(
        "Resolution: "
            + Display.getDisplayMode().getWidth()
            + "x"
            + Display.getDisplayMode().getHeight()
            + "x"
            + Display.getDisplayMode().getBitsPerPixel()
            + "@"
            + Display.getDisplayMode().getFrequency()
            + "Hz");

    pause(5000);

    // reset
    System.out.print("Resetting mode...");
    try {
      Display.setFullscreen(false);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
    System.out.println("done");

    System.out.println("---- Test setDisplayMode ----");
  }
示例#15
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);
  }