/**
   * Create the native window peer from the given mode and fullscreen flag. A native context must
   * exist, and it will be attached to the window.
   */
  private static void createWindow() throws LWJGLException {
    if (window_created) {
      return;
    }
    Canvas tmp_parent = isFullscreen() ? null : parent;
    if (tmp_parent != null
        && !tmp_parent
            .isDisplayable()) // Only a best effort check, since the parent can turn undisplayable
                              // hereafter
    throw new LWJGLException("Parent.isDisplayable() must be true");
    if (tmp_parent != null) {
      tmp_parent.addComponentListener(component_listener);
    }
    DisplayMode mode = getEffectiveMode();
    display_impl.createWindow(drawable, mode, tmp_parent, getWindowX(), getWindowY());
    window_created = true;

    width = Display.getDisplayMode().getWidth();
    height = Display.getDisplayMode().getHeight();

    setTitle(title);
    initControls();

    // set cached window icon if exists
    if (cached_icons != null) {
      setIcon(cached_icons);
    } else {
      setIcon(new ByteBuffer[] {LWJGLUtil.LWJGLIcon32x32, LWJGLUtil.LWJGLIcon16x16});
    }
  }
  /**
   * @return this method will return the height of the Display window.
   *     <p>If running in fullscreen mode it will return the height of the current set DisplayMode.
   *     If Display.setParent(Canvas parent) is being used, the height of the parent will be
   *     returned.
   *     <p>This value will be updated after a call to Display.update().
   */
  public static int getHeight() {

    if (Display.isFullscreen()) {
      return Display.getDisplayMode().getHeight();
    }

    if (parent != null) {
      return parent.getHeight();
    }

    return height;
  }
  /**
   * @return this method will return the width of the Display window.
   *     <p>If running in fullscreen mode it will return the width of the current set DisplayMode.
   *     If Display.setParent(Canvas parent) is being used, the width of the parent will be
   *     returned.
   *     <p>This value will be updated after a call to Display.update().
   */
  public static int getWidth() {

    if (Display.isFullscreen()) {
      return Display.getDisplayMode().getWidth();
    }

    if (parent != null) {
      return parent.getWidth();
    }

    return width;
  }
Exemple #4
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();
   }
 }
Exemple #5
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());
   }
 }