示例#1
0
  /*
   * Called when the application is alt-tabbed to or from
   */
  private void appActivate(boolean active) {
    if (inAppActivate) {
      return;
    }
    inAppActivate = true;
    isFocused = active;
    if (active) {
      if (Display.isFullscreen()) {
        restoreDisplayMode();
      }
      if (parent == null) {
        setForegroundWindow(getHwnd());
      }
      setFocus(getHwnd());
      redoMakeContextCurrent = true;
      if (Display.isFullscreen()) updateClipping();

      if (keyboard != null) keyboard.fireLostKeyEvents();
    } else if (Display.isFullscreen()) {
      showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
      resetDisplayMode();
    } else updateClipping();
    updateCursor();
    inAppActivate = false;
  }
  /**
   * 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 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;
  }
  /**
   * @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;
  }
示例#5
0
 public void shutdownMinecraftApplet() {
   try {
     statFileWriter.func_27175_b();
     statFileWriter.syncStats();
     if (mcApplet != null) {
       mcApplet.clearApplet();
     }
     try {
       if (downloadResourcesThread != null) {
         downloadResourcesThread.closeMinecraft();
       }
     } catch (Exception exception) {
     }
     System.out.println("Stopping!");
     try {
       changeWorld1(null);
     } catch (Throwable throwable) {
     }
     try {
       GLAllocation.deleteTexturesAndDisplayLists();
     } catch (Throwable throwable1) {
     }
     sndManager.closeMinecraft();
     Mouse.destroy();
     Keyboard.destroy();
   } finally {
     Display.destroy();
     if (!hasCrashed) {
       System.exit(0);
     }
   }
   System.gc();
 }
示例#6
0
  public void setResizable(boolean resizable) {
    if (this.resizable != resizable) {
      int style = (int) getWindowLongPtr(hwnd, GWL_STYLE);
      int styleex = (int) getWindowLongPtr(hwnd, GWL_EXSTYLE);

      // update frame style
      if (resizable && !Display.isFullscreen()) {
        setWindowLongPtr(hwnd, GWL_STYLE, style |= (WS_THICKFRAME | WS_MAXIMIZEBOX));
      } else {
        setWindowLongPtr(hwnd, GWL_STYLE, style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX));
      }

      // from the existing client rect, determine the new window rect
      // based on the style changes - using AdjustWindowRectEx.
      getClientRect(hwnd, rect_buffer);
      rect.copyFromBuffer(rect_buffer);
      adjustWindowRectEx(rect_buffer, style, false, styleex);
      rect.copyFromBuffer(rect_buffer);

      // force a frame update and resize accordingly
      setWindowPos(
          hwnd,
          HWND_TOP,
          0,
          0,
          rect.right - rect.left,
          rect.bottom - rect.top,
          SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);

      updateWidthAndHeight();
      resized = false;
    }
    this.resizable = resizable;
  }
 public void show(Graphics g) {
   // System.out.println("Showing ...");
   Bar b = (Bar) getDisplayElement(s1);
   Rectangle r = new Rectangle(b.getLocation(), b.getSize());
   r.y += r.height;
   Rectangle r2 = ((TextElement) getDisplayElement(s5)).fitToRect(g, "SansSerif", Font.PLAIN, r);
   r2.y += r2.height;
   ((TextElement) getDisplayElement(s6)).fitToRect(g, "SansSerif", Font.PLAIN, r2);
   super.show(g);
 }
  /**
   * @return this method will return the y position (top-left) of the Display window.
   *     <p>If running in fullscreen mode it will return 0. If Display.setParent(Canvas parent) is
   *     being used, the y position of the parent will be returned.
   */
  public static int getY() {

    if (Display.isFullscreen()) {
      return 0;
    }

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

    return display_impl.getY();
  }
示例#9
0
 private void updateClipping() {
   if ((Display.isFullscreen() || (mouse != null && mouse.isGrabbed()))
       && !isMinimized
       && isFocused
       && (getForegroundWindow() == getHwnd() || hasParent)) {
     try {
       setupCursorClipping(getHwnd());
     } catch (LWJGLException e) {
       LWJGLUtil.log("setupCursorClipping failed: " + e.getMessage());
     }
   } else {
     resetCursorClipping();
   }
 }
示例#10
0
 public void setIngameFocus() {
   if (!Display.isActive()) {
     return;
   }
   if (inGameHasFocus) {
     return;
   } else {
     inGameHasFocus = true;
     mouseHelper.grabMouseCursor();
     displayGuiScreen(null);
     leftClickCounter = 10000;
     mouseTicksRan = ticksRan + 10000;
     return;
   }
 }
示例#11
0
 private void loadScreen() throws LWJGLException {
   ScaledResolution scaledresolution =
       new ScaledResolution(gameSettings, displayWidth, displayHeight);
   GL11.glClear(16640);
   GL11.glMatrixMode(5889 /*GL_PROJECTION*/);
   GL11.glLoadIdentity();
   GL11.glOrtho(
       0.0D, scaledresolution.field_25121_a, scaledresolution.field_25120_b, 0.0D, 1000D, 3000D);
   GL11.glMatrixMode(5888 /*GL_MODELVIEW0_ARB*/);
   GL11.glLoadIdentity();
   GL11.glTranslatef(0.0F, 0.0F, -2000F);
   GL11.glViewport(0, 0, displayWidth, displayHeight);
   GL11.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
   Tessellator tessellator = Tessellator.instance;
   GL11.glDisable(2896 /*GL_LIGHTING*/);
   GL11.glEnable(3553 /*GL_TEXTURE_2D*/);
   GL11.glDisable(2912 /*GL_FOG*/);
   GL11.glBindTexture(3553 /*GL_TEXTURE_2D*/, renderEngine.getTexture("/title/mojang.png"));
   tessellator.startDrawingQuads();
   tessellator.setColorOpaque_I(0xffffff);
   tessellator.addVertexWithUV(0.0D, displayHeight, 0.0D, 0.0D, 0.0D);
   tessellator.addVertexWithUV(displayWidth, displayHeight, 0.0D, 0.0D, 0.0D);
   tessellator.addVertexWithUV(displayWidth, 0.0D, 0.0D, 0.0D, 0.0D);
   tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
   tessellator.draw();
   char c = '\u0100';
   char c1 = '\u0100';
   GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
   tessellator.setColorOpaque_I(0xffffff);
   func_6274_a(
       (scaledresolution.getScaledWidth() - c) / 2,
       (scaledresolution.getScaledHeight() - c1) / 2,
       0,
       0,
       c,
       c1);
   GL11.glDisable(2896 /*GL_LIGHTING*/);
   GL11.glDisable(2912 /*GL_FOG*/);
   GL11.glEnable(3008 /*GL_ALPHA_TEST*/);
   GL11.glAlphaFunc(516, 0.1F);
   Display.swapBuffers();
 }
示例#12
0
  public void update() {
    nUpdate();

    if (!isFocused && parent != null && parent_focused.compareAndSet(true, false)) {
      setFocus(getHwnd());
    }

    if (redoMakeContextCurrent) {
      redoMakeContextCurrent = false;
      /**
       * WORKAROUND: Making the context current (redundantly) when the window is maximized helps
       * some gfx cards recover from fullscreen
       */
      try {
        Context context = ((DrawableLWJGL) Display.getDrawable()).getContext();
        if (context != null && context.isCurrent()) context.makeCurrent();
      } catch (LWJGLException e) {
        LWJGLUtil.log("Exception occurred while trying to make context current: " + e);
      }
    }
  }
示例#13
0
  /**
   * Sets one or more icons for the Display.
   *
   * <ul>
   *   <li>On Windows you should supply at least one 16x16 icon and one 32x32.
   *   <li>Linux (and similar platforms) expect one 32x32 icon.
   *   <li>Mac OS X should be supplied one 128x128 icon
   * </ul>
   *
   * The implementation will use the supplied ByteBuffers with image data in RGBA (size must be a
   * power of two) and perform any conversions nescesarry for the specific platform.
   *
   * <p><b>NOTE:</b> The display will make a deep copy of the supplied byte buffer array, for the
   * purpose of recreating the icons when you go back and forth fullscreen mode. You therefore only
   * need to set the icon once per instance.
   *
   * @param icons Array of icons in RGBA mode. Pass the icons in order of preference.
   * @return number of icons used, or 0 if display hasn't been created
   */
  public static int setIcon(ByteBuffer[] icons) {
    synchronized (GlobalLock.lock) {
      // make deep copy so we dont rely on the supplied buffers later on
      // don't recache!
      if (cached_icons != icons) {
        cached_icons = new ByteBuffer[icons.length];
        for (int i = 0; i < icons.length; i++) {
          cached_icons[i] = BufferUtils.createByteBuffer(icons[i].capacity());
          int old_position = icons[i].position();
          cached_icons[i].put(icons[i]);
          icons[i].position(old_position);
          cached_icons[i].flip();
        }
      }

      if (Display.isCreated() && parent == null) {
        return display_impl.setIcon(cached_icons);
      } else {
        return 0;
      }
    }
  }
示例#14
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();
   }
 }
示例#15
0
  public void run() {
    running = true;
    try {
      startGame();
    } catch (Exception exception) {
      exception.printStackTrace();
      onMinecraftCrash(new UnexpectedThrowable("Failed to start game", exception));
      return;
    }
    try {
      long l = System.currentTimeMillis();
      int i = 0;
      do {
        if (!running) {
          break;
        }
        try {
          if (mcApplet != null && !mcApplet.isActive()) {
            break;
          }
          AxisAlignedBB.clearBoundingBoxPool();
          Vec3D.initialize();
          if (mcCanvas == null && Display.isCloseRequested()) {
            shutdown();
          }
          if (isGamePaused && theWorld != null) {
            float f = timer.renderPartialTicks;
            timer.updateTimer();
            timer.renderPartialTicks = f;
          } else {
            timer.updateTimer();
          }
          long l1 = System.nanoTime();
          for (int j = 0; j < timer.elapsedTicks; j++) {
            ticksRan++;
            try {
              runTick();
              continue;
            } catch (MinecraftException minecraftexception1) {
              theWorld = null;
            }
            changeWorld1(null);
            displayGuiScreen(new GuiConflictWarning());
          }

          long l2 = System.nanoTime() - l1;
          checkGLError("Pre render");
          RenderBlocks.fancyGrass = gameSettings.fancyGraphics;
          sndManager.func_338_a(thePlayer, timer.renderPartialTicks);
          GL11.glEnable(3553 /*GL_TEXTURE_2D*/);
          if (theWorld != null) {
            theWorld.updatingLighting();
          }
          if (!Keyboard.isKeyDown(65)) {
            Display.update();
          }
          if (thePlayer != null && thePlayer.isEntityInsideOpaqueBlock()) {
            gameSettings.thirdPersonView = false;
          }
          if (!skipRenderWorld) {
            if (playerController != null) {
              playerController.setPartialTime(timer.renderPartialTicks);
            }
            entityRenderer.updateCameraAndRender(timer.renderPartialTicks);
          }
          if (!Display.isActive()) {
            if (fullscreen) {
              toggleFullscreen();
            }
            Thread.sleep(10L);
          }
          if (gameSettings.showDebugInfo) {
            displayDebugInfo(l2);
          } else {
            prevFrameTime = System.nanoTime();
          }
          guiAchievement.updateAchievementWindow();
          Thread.yield();
          if (Keyboard.isKeyDown(65)) {
            Display.update();
          }
          screenshotListener();
          if (mcCanvas != null
              && !fullscreen
              && (mcCanvas.getWidth() != displayWidth || mcCanvas.getHeight() != displayHeight)) {
            displayWidth = mcCanvas.getWidth();
            displayHeight = mcCanvas.getHeight();
            if (displayWidth <= 0) {
              displayWidth = 1;
            }
            if (displayHeight <= 0) {
              displayHeight = 1;
            }
            resize(displayWidth, displayHeight);
          }
          checkGLError("Post render");
          i++;
          isGamePaused =
              !isMultiplayerWorld() && currentScreen != null && currentScreen.doesGuiPauseGame();
          while (System.currentTimeMillis() >= l + 1000L) {
            debug =
                (new StringBuilder())
                    .append(i)
                    .append(" fps, ")
                    .append(WorldRenderer.chunksUpdated)
                    .append(" chunk updates")
                    .toString();
            WorldRenderer.chunksUpdated = 0;
            l += 1000L;
            i = 0;
          }
        } catch (MinecraftException minecraftexception) {
          theWorld = null;
          changeWorld1(null);
          displayGuiScreen(new GuiConflictWarning());
        } catch (OutOfMemoryError outofmemoryerror) {
          func_28002_e();
          displayGuiScreen(new GuiErrorScreen());
          System.gc();
        }
      } while (true);
    } catch (MinecraftError minecrafterror) {
    } catch (Throwable throwable) {
      func_28002_e();
      throwable.printStackTrace();
      onMinecraftCrash(new UnexpectedThrowable("Unexpected error", throwable));
    } finally {
      shutdownMinecraftApplet();
    }
  }
示例#16
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());
   }
 }
示例#17
0
  public void createWindow(DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y)
      throws LWJGLException {
    close_requested = false;
    is_dirty = false;
    isMinimized = false;
    isFocused = false;
    redoMakeContextCurrent = false;
    maximized = false;
    this.parent = parent;
    hasParent = parent != null;
    parent_hwnd = parent != null ? getHwnd(parent) : 0;
    this.hwnd =
        nCreateWindow(
            x,
            y,
            mode.getWidth(),
            mode.getHeight(),
            Display.isFullscreen() || isUndecorated(),
            parent != null,
            parent_hwnd);
    this.resizable = false;
    if (hwnd == 0) {
      throw new LWJGLException("Failed to create window");
    }
    this.hdc = getDC(hwnd);
    if (hdc == 0) {
      nDestroyWindow(hwnd);
      throw new LWJGLException("Failed to get dc");
    }

    try {
      if (drawable instanceof DrawableGL) {
        int format =
            WindowsPeerInfo.choosePixelFormat(
                getHdc(),
                0,
                0,
                (PixelFormat) drawable.getPixelFormat(),
                null,
                true,
                true,
                false,
                true);
        WindowsPeerInfo.setPixelFormat(getHdc(), format);
      } else {
        peer_info = new WindowsDisplayPeerInfo(true);
        ((DrawableGLES) drawable)
            .initialize(
                hwnd,
                hdc,
                EGL.EGL_WINDOW_BIT,
                (org.lwjgl.opengles.PixelFormat) drawable.getPixelFormat());
      }
      peer_info.initDC(getHwnd(), getHdc());
      showWindow(getHwnd(), SW_SHOWDEFAULT);

      updateWidthAndHeight();

      if (parent == null) {
        if (Display.isResizable()) {
          setResizable(true);
        }
        setForegroundWindow(getHwnd());
      } else {
        parent_focused = new AtomicBoolean(false);
        parent.addFocusListener(
            parent_focus_tracker =
                new FocusAdapter() {
                  public void focusGained(FocusEvent e) {
                    parent_focused.set(true);
                    clearAWTFocus();
                  }
                });
        SwingUtilities.invokeLater(
            new Runnable() {
              public void run() {
                clearAWTFocus();
              }
            });
      }
      grabFocus();
    } catch (LWJGLException e) {
      nReleaseDC(hwnd, hdc);
      nDestroyWindow(hwnd);
      throw e;
    }
  }
示例#18
0
 public static void main(String[] args) throws IOException {
   Display myWindow = new Display("Hough Circle");
   myWindow.setSize(800, 600);
   myWindow.setVisible(true);
 }
示例#19
0
 private static boolean isUndecorated() {
   return Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated");
 }
示例#20
0
 public void reshape(int x, int y, int width, int height) {
   nReshape(
       getHwnd(), x, y, width, height, Display.isFullscreen() || isUndecorated(), parent != null);
 }