示例#1
0
  public Render(Level level) {
    this.level = level;
    try {
      Display.setFullscreen(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    // Enable vsync if we can
    Display.setVSyncEnabled(true);

    try {
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    // Put the window into orthographic projection mode with 1:1 pixel
    // ratio.
    // We haven't used GLU here to do this to avoid an unnecessary
    // dependency.

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(
        0.0,
        Display.getDisplayMode().getWidth(),
        0.0,
        Display.getDisplayMode().getHeight(),
        -1.0,
        1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
  }
示例#2
0
  /** Tests the DisplayConfiguration */
  private void setDisplayConfigurationTest() {
    System.out.println("==== Test setDisplayConfigurationTest ====");

    System.out.println("Testing normal setting");
    changeConfig(1.0f, 0f, 1f);

    System.out.println("Testing gamma settings");
    changeConfig(5.0f, 0f, 1f);
    changeConfig(0.5f, 0f, 1f);

    System.out.println("Testing brightness settings");
    changeConfig(1.0f, -1.0f, 1f);
    changeConfig(1.0f, -0.5f, 1f);
    changeConfig(1.0f, 0.5f, 1f);
    changeConfig(1.0f, 1.0f, 1f);

    System.out.println("Testing contrast settings");
    changeConfig(1.0f, 0f, 0f);
    changeConfig(1.0f, 0f, 0.5f);
    changeConfig(1.0f, 0f, 10000.0f);

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

    System.out.println("---- Test setDisplayConfigurationTest ----");
  }
示例#3
0
  /**
   * Initialise the game
   *
   * @throws Exception if init fails
   */
  private static void init() throws Exception {
    // Create a fullscreen window with 1:1 orthographic 2D projection, and with
    // mouse, keyboard, and gamepad inputs.
    Display.setTitle(GAME_TITLE);
    Display.setFullscreen(true);

    // Enable vsync if we can
    Display.setVSyncEnabled(true);

    Display.create();

    // Start up the sound system
    AL.create();

    // TODO: Load in your textures etc here

    // Put the window into orthographic projection mode with 1:1 pixel ratio.
    // We haven't used GLU here to do this to avoid an unnecessary dependency.
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(
        0.0,
        Display.getDisplayMode().getWidth(),
        0.0,
        Display.getDisplayMode().getHeight(),
        -1.0,
        1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
  }
示例#4
0
 private void initGL() {
   try {
     Display.setDisplayMode(new DisplayMode(GS.FRAMEWIDTH, GS.FRAMEHEIGHT));
     Display.setFullscreen(true);
     Display.create();
     Display.setVSyncEnabled(true);
   } catch (LWJGLException e) {
     e.printStackTrace();
     Display.destroy();
     System.exit(1);
   }
   GL11.glEnable(GL11.GL_TEXTURE_2D);
   // GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
   GL11.glClearDepth(1.0f);
   // GL11.glEnable(GL11.GL_DEPTH_TEST);
   // GL11.glDepthFunc(GL11.GL_ADD); //Wenn nicht auskommentiert führt es zu Exception
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glViewport(0, 0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT);
   GL11.glOrtho(0, GS.FRAMEWIDTH, GS.FRAMEHEIGHT, 0, 0, 128);
   GL11.glEnable(GL11.GL_BLEND);
   GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
   // GL11.glBlendEquation( BLENDING_EQUATIONS[blendingEquationIndex]);
   GL11.glShadeModel(GL11.GL_FLAT);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glEnable(GL11.GL_ALPHA_TEST);
   GL11.glAlphaFunc(GL11.GL_GREATER, 0);
   GL11.glCullFace(GL11.GL_BACK);
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   GL11.glLoadIdentity();
 }
示例#5
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);
    }
  }
示例#6
0
  private void init(boolean absolutePixels, boolean testModes) {
    // find out what the current bits per pixel of the desktop is
    int currentBpp = Display.getDisplayMode().getBitsPerPixel();

    try {
      DisplayMode mode;
      if (testModes) mode = findDisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT, currentBpp);
      else mode = new DisplayMode(WINDOW_WIDTH, WINDOW_HEIGHT);

      Display.setDisplayMode(mode);
      Display.setFullscreen(false);
      Display.setTitle("src");
      Display.create();
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    double aspectRatio = (double) WINDOW_WIDTH / WINDOW_HEIGHT;

    if (absolutePixels) {
      glOrtho(0.0d, WINDOW_WIDTH, 0.0d, WINDOW_HEIGHT, 1.0d, -1.0d);
    } else {
      glOrtho(aspectRatio, -aspectRatio, -1.0d, 1.0d, 1.0d, -1.0d);
    }

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
  }
示例#7
0
 public static void toggleFullscreen() {
   Globals.fullscreen = !Globals.fullscreen;
   try {
     Display.setFullscreen(Globals.fullscreen);
     Display.update();
   } catch (LWJGLException e) {
     e.printStackTrace();
   }
 }
示例#8
0
 @Override
 public void setFullscreen(final boolean fullscreen) {
   try {
     Display.setFullscreen(fullscreen);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
  /**
   * 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);
    }
  }
示例#10
0
 private void createWindow() {
   try {
     Display.setDisplayMode(DISPLAY_MODE);
     Display.setFullscreen(fullscreen);
     Display.setTitle(WINDOW_TITLE);
     Display.create();
   } catch (LWJGLException e) {
     e.printStackTrace();
   }
 }
示例#11
0
文件: Game.java 项目: Woutwo/Project1
  public void start() {
    try {
      Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
      Display.create();
      Display.setFullscreen(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(0);
    }

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glEnable(GL11.GL_BLEND);
    GL11.glEnable(GL11.GL_ALPHA);
    GL11.glEnable(GL11.GL_ALPHA_TEST);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);

    GL11.glClearAccum(0f, 0f, 0f, 1f);
    GL11.glClear(GL11.GL_ACCUM_BUFFER_BIT);

    while (!Display.isCloseRequested() && !finished) {
      if (System.currentTimeMillis() - time > 1000) {
        System.out.println(framecount + " FPS");
        time = System.currentTimeMillis();
        framecount = 0;
      }

      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

      GL11.glColor3f(1, 1, 1);

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10);
      Manager.DrawBackground();

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10);

      GL11.glTranslatef(-Camera.x, -Camera.y, 0);
      Display.sync(60);

      Manager.Draw();
      Manager.Update();

      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, WIDTH, HEIGHT, 0, -10, 10);
      Manager.DrawForeground();

      Display.update();

      framecount++;
    }
  }
示例#12
0
 public static void setFullscreen(boolean fullscreen) {
   try {
     if (fullscreen) {
       displayMode = Display.getDisplayMode();
       Display.setDisplayMode(Display.getDesktopDisplayMode());
     } else {
       Display.setDisplayMode(displayMode);
     }
     Display.setFullscreen(fullscreen);
   } catch (LWJGLException e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
示例#13
0
  public void initGL() {
    // Setup Display
    try {
      if (display_parent != null) {
        Display.setParent(display_parent);
      }
      Display.setDisplayMode(new DisplayMode(1000, 1000));
      Display.create(new PixelFormat(24, 8, 24, 0, 0));
      Display.setTitle("JGE3d");

      // Create a fullscreen window with 1:1 orthographic 2D projection
      // (default)
      Display.setFullscreen(false);

      // Enable vsync if we can (due to how OpenGL works, it cannot be
      // guarenteed to always work)
      // TODO: Make Configurable by User
      Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }
    window_manager = new WindowManager();

    // camera = (Camera) objectList.getItem(Camera.CAMERA_NAME);

    setPerspective();

    // Set default openGL for drawing
    // GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);

    // Initialize default settings
    ByteBuffer temp = ByteBuffer.allocateDirect(16);
    temp.order(ByteOrder.nativeOrder());

    if (GLContext.getCapabilities().GL_ARB_vertex_buffer_object) {
      supports_vbo = true;
    } else {
      supports_vbo = false;
    }

    // Blending functions so we can have transparency
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    GL11.glEnable(GL11.GL_BLEND);
  }
示例#14
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;
  }
示例#15
0
  public void update() {
    Display.update();
    Display.sync(fps);
    detectKonami();

    if (Constants.allowFullScr) {
      if ((fullScr && !Display.isFullscreen()) || (!fullScr && Display.isFullscreen())) {
        System.out.println("Performing Display.destroy()/create() cycle");
        sM = Display.getDisplayMode();
        Display.destroy();
        try {
          //					DisplayMode[] d = Display.getAvailableDisplayModes();
          //					int value = 0;
          //					int index = 0;
          //					for(int i = 0; i < d.length; i++){
          //						if(d[i].getWidth() > value){
          //							value = d[i].getWidth();
          //							index = i;
          //						}
          //					}
          Display.setDisplayMode(sM);
          Display.setTitle("Music Dots");
          Display.setFullscreen(fullScr);
          Display.create();
          Display.setVSyncEnabled(true);
          Constants.VIEW_HEIGHT = sM.getHeight();
          Constants.VIEW_WIDTH = sM.getWidth();
          setupOpenGl();
          Fonts.initialize();
        } catch (LWJGLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }

    Theme.setClearColor();

    // TODO: we should be calling a "recreateView" function and call this in there. Not sure why
    // we're recreating the view in an update function.
    if (!bPlayerModelInitialized) {
      StaticDrawer.initializeTextures();
      bPlayerModelInitialized = true;
    }

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  }
示例#16
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();
    }
  }
示例#17
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);
   }
 }
示例#18
0
 public void toggleFullscreen() {
   try {
     fullscreen = !fullscreen;
     if (fullscreen) {
       Display.setDisplayMode(Display.getDesktopDisplayMode());
       displayWidth = Display.getDisplayMode().getWidth();
       displayHeight = Display.getDisplayMode().getHeight();
       if (displayWidth <= 0) {
         displayWidth = 1;
       }
       if (displayHeight <= 0) {
         displayHeight = 1;
       }
     } else {
       if (mcCanvas != null) {
         displayWidth = mcCanvas.getWidth();
         displayHeight = mcCanvas.getHeight();
       } else {
         displayWidth = tempDisplayWidth;
         displayHeight = tempDisplayHeight;
       }
       if (displayWidth <= 0) {
         displayWidth = 1;
       }
       if (displayHeight <= 0) {
         displayHeight = 1;
       }
     }
     if (currentScreen != null) {
       resize(displayWidth, displayHeight);
     }
     Display.setFullscreen(fullscreen);
     Display.update();
   } catch (Exception exception) {
     exception.printStackTrace();
   }
 }
示例#19
0
  private void initGL(int width, int height) {

    try {
      // DisplayMode mode = new DisplayMode(width,height);
      // DisplayMode mode = Display.getDesktopDisplayMode(); Old code, for not-fullscreen stuff
      Display.setDisplayMode(Display.getDesktopDisplayMode());
      Display.setFullscreen(true);
      Display.create();
      Display.setVSyncEnabled(true);
    } catch (LWJGLException e) {
      System.out.println("Catched an error in intiGL");
      e.printStackTrace();
      System.exit(0);
    }

    // init OpenGL
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GL11.glOrtho(0, width, 0, height, 1, -1);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    GL11.glEnable(GL11.GL_BLEND);
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  }
示例#20
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);
  }
示例#21
0
 public void startGame() throws LWJGLException {
   if (mcCanvas != null) {
     Graphics g = mcCanvas.getGraphics();
     if (g != null) {
       g.setColor(Color.BLACK);
       g.fillRect(0, 0, displayWidth, displayHeight);
       g.dispose();
     }
     Display.setParent(mcCanvas);
   } else if (fullscreen) {
     Display.setFullscreen(true);
     displayWidth = Display.getDisplayMode().getWidth();
     displayHeight = Display.getDisplayMode().getHeight();
     if (displayWidth <= 0) {
       displayWidth = 1;
     }
     if (displayHeight <= 0) {
       displayHeight = 1;
     }
   } else {
     Display.setDisplayMode(new DisplayMode(displayWidth, displayHeight));
   }
   Display.setTitle("Minecraft Minecraft Beta 1.7.3");
   try {
     Display.create();
   } catch (LWJGLException lwjglexception) {
     lwjglexception.printStackTrace();
     try {
       Thread.sleep(1000L);
     } catch (InterruptedException interruptedexception) {
     }
     Display.create();
   }
   mcDataDir = getMinecraftDir();
   saveLoader = new SaveConverterMcRegion(new File(mcDataDir, "saves"));
   gameSettings = new GameSettings(this, mcDataDir);
   texturePackList = new TexturePackList(this, mcDataDir);
   renderEngine = new RenderEngine(texturePackList, gameSettings);
   fontRenderer = new FontRenderer(gameSettings, "/font/default.png", renderEngine);
   ColorizerWater.func_28182_a(renderEngine.func_28149_a("/misc/watercolor.png"));
   ColorizerGrass.func_28181_a(renderEngine.func_28149_a("/misc/grasscolor.png"));
   ColorizerFoliage.func_28152_a(renderEngine.func_28149_a("/misc/foliagecolor.png"));
   entityRenderer = new EntityRenderer(this);
   RenderManager.instance.itemRenderer = new ItemRenderer(this);
   statFileWriter = new StatFileWriter(session, mcDataDir);
   AchievementList.openInventory.setStatStringFormatter(new StatStringFormatKeyInv(this));
   loadScreen();
   Keyboard.create();
   Mouse.create();
   mouseHelper = new MouseHelper(mcCanvas);
   try {
     Controllers.create();
   } catch (Exception exception) {
     exception.printStackTrace();
   }
   checkGLError("Pre startup");
   GL11.glEnable(3553 /*GL_TEXTURE_2D*/);
   GL11.glShadeModel(7425 /*GL_SMOOTH*/);
   GL11.glClearDepth(1.0D);
   GL11.glEnable(2929 /*GL_DEPTH_TEST*/);
   GL11.glDepthFunc(515);
   GL11.glEnable(3008 /*GL_ALPHA_TEST*/);
   GL11.glAlphaFunc(516, 0.1F);
   GL11.glCullFace(1029 /*GL_BACK*/);
   GL11.glMatrixMode(5889 /*GL_PROJECTION*/);
   GL11.glLoadIdentity();
   GL11.glMatrixMode(5888 /*GL_MODELVIEW0_ARB*/);
   checkGLError("Startup");
   glCapabilities = new OpenGlCapsChecker();
   sndManager.loadSoundSettings(gameSettings);
   renderEngine.registerTextureFX(textureLavaFX);
   renderEngine.registerTextureFX(textureWaterFX);
   renderEngine.registerTextureFX(new TexturePortalFX());
   renderEngine.registerTextureFX(new TextureCompassFX(this));
   renderEngine.registerTextureFX(new TextureWatchFX(this));
   renderEngine.registerTextureFX(new TextureWaterFlowFX());
   renderEngine.registerTextureFX(new TextureLavaFlowFX());
   renderEngine.registerTextureFX(new TextureFlamesFX(0));
   renderEngine.registerTextureFX(new TextureFlamesFX(1));
   renderGlobal = new RenderGlobal(this, renderEngine);
   GL11.glViewport(0, 0, displayWidth, displayHeight);
   effectRenderer = new EffectRenderer(theWorld, renderEngine);
   try {
     downloadResourcesThread = new ThreadDownloadResources(mcDataDir, this);
     downloadResourcesThread.start();
   } catch (Exception exception1) {
   }
   checkGLError("Post startup");
   ingameGUI = new GuiIngame(this);
   if (serverName != null) {
     displayGuiScreen(new GuiConnecting(this, serverName, serverPort));
   } else {
     displayGuiScreen(new GuiMainMenu());
   }
 }
示例#22
0
文件: LLC.java 项目: JackdDvice/LLC
 /** Toggles the game into fullscreen mode */
 private void toggleFullscreen() throws LWJGLException {
   this.isFullscreen = !this.isFullscreen;
   Display.setDisplayMode(
       this.isFullscreen ? Display.getDesktopDisplayMode() : standartDisplayMode);
   Display.setFullscreen(this.isFullscreen);
 }
示例#23
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 ----");
  }