Пример #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
  /**
   * 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});
    }
  }
Пример #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());
  }
  /**
   * *************************************************************************************************************************************************************************************************
   * Initialization stuff comes in here...
   * ************************************************************************************************************************************************************************************************
   */
  private void init() {

    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setVSyncEnabled(true);
      Display.setTitle("MS3D Loader [G36C]");
      Display.create();

      Keyboard.create();

    } catch (LWJGLException e) {
      Sys.alert("Error", "Initialization failed!\n\n" + e.getMessage());
      System.exit(0);
    }

    /* OpenGL */
    int width = Display.getDisplayMode().getWidth();
    int height = Display.getDisplayMode().getHeight();

    GL11.glViewport(0, 0, width, height); // Reset The Current Viewport
    GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
    GL11.glLoadIdentity(); // Reset The Projection Matrix
    GLU.gluPerspective(
        45.0f,
        ((float) width / (float) height),
        0.1f,
        1000.0f); // Calculate The Aspect Ratio Of The Window
    GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
    GL11.glLoadIdentity(); // Reset The Modelview Matrix

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Background color
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    // Load model
    //		g36c = new
    // MS3DModel(resourceLoader.loadResourceAsStream("models/gsg9.ms3d"),this.getClass().getResource("./data/textures").getPath());
    g36c =
        new MS3DModel(
            resourceLoader.loadResourceAsStream("models/assassin.ms3d"),
            this.getClass().getResource("./data/textures").getPath());

    //		tdsLoader=new TDSLoader();
    //		try {
    //			tdsLoader.load(resourceLoader.loadResourceAsStream("models/face.3ds"));
    //			System.out.println(tdsLoader.getObjectSize());
    //		} catch (IOException e) {
    //			e.printStackTrace();
    //		}

    // Load font
    font = new Font(resourceLoader.loadResourceAsStream("textures/font.bmp"), 12, width, height);

    // Init timer
    timer = new Timer();
  }
  /**
   * 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);
    }
  }
Пример #6
0
 private void globaldraw() {
   GL11.glMatrixMode(GL11.GL_PROJECTION);
   GL11.glLoadIdentity();
   GL11.glOrtho(
       0, Display.getDisplayMode().getWidth(), 0, Display.getDisplayMode().getHeight(), -1, 1);
   GL11.glMatrixMode(GL11.GL_MODELVIEW);
   GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_STENCIL_BUFFER_BIT);
   for (int i = 0; i < blocks.size(); i++) blocks.get(i).onDraw(xorig);
   player.onDraw();
   Display.sync(120);
   setPoints();
 }
Пример #7
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();
  }
Пример #8
0
  /** Render the current frame */
  private static void render() {
    glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    // TODO: all your rendering goes here
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glTranslatef(
        Display.getDisplayMode().getWidth() / 2, Display.getDisplayMode().getHeight() / 2, 0.0f);
    glRotatef(angle, 0, 0, 1.0f);
    glBegin(GL_QUADS);
    glVertex2i(-50, -50);
    glVertex2i(50, -50);
    glVertex2i(50, 50);
    glVertex2i(-50, 50);
    glEnd();
    glPopMatrix();
  }
Пример #9
0
  /** Prints some info about the current mode */
  private void currentTest() {
    System.out.println("==== Test Current ====");

    System.out.println("Info about current:");
    System.out.println(
        "Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion());
    System.out.println(
        "Resolution: "
            + Display.getDisplayMode().getWidth()
            + "x"
            + Display.getDisplayMode().getHeight()
            + "x"
            + Display.getDisplayMode().getBitsPerPixel()
            + "@"
            + Display.getDisplayMode().getFrequency()
            + "Hz");
    System.out.println("---- Test Current ----");
  }
Пример #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
  /**
   * @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;
  }
Пример #12
0
  /**
   * @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;
  }
Пример #13
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);
   }
 }
Пример #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 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);
  }
  /**
   * 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) {
    }
  }
Пример #17
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();
    }
  }
Пример #18
0
  /**
   * Called when the screen is resized, and sets some variables, like {@link JumboMathHandler#xmod}
   * and {@link JumboMathHandler#ymod}.
   */
  public static void update() {
    // JumboLaunchConfig config = JumboSettings.launchConfig;
    final int width, height;
    final float factor;
    if (JumboSettings.launchConfig.fullscreen) {
      final DisplayMode current = Display.getDisplayMode();
      factor = Display.getPixelScaleFactor();
      width = current.getWidth();
      height = current.getHeight();
    } else {
      width = Display.getWidth();
      height = Display.getHeight();
      factor = Display.getPixelScaleFactor();
    }
    // Dynamic resizing only works if its larger than the launch
    // dimensions.
    // If its not, it gets strectched, which looks a bit ugly. Because
    // of
    // this, developers should make their base window as small as
    // possible.
    // if (width < config.width || height < config.height) {
    // renderwidth = config.width;
    // renderheight = config.height;
    // GL11.glOrtho(0.0f, config.width, 0, config.height, 0.0f, 1.0f);
    // GL11.glViewport(0, 0, width, height);
    // Maths.currentdim = new Dimension(config.width, config.height);
    // } else {
    // for high dpi modes
    renderwidth = (int) (width * factor);
    renderheight = (int) (height * factor);

    for (JumboRenderModule m : modes) {
      m.resize(renderwidth, renderheight);
    }

    JumboPaintClass.getScene().onWindowUpdate();
    JumboPaintClass.getPreviousScene().onWindowUpdate();
    wasResized = false;
  }
Пример #19
0
  private void init() throws LWJGLException {
    // create Window of size 800x600
    Display.setDisplayMode(new DisplayMode(1024, 768));
    Display.setLocation(
        (Display.getDisplayMode().getWidth() - 300) / 2,
        (Display.getDisplayMode().getHeight() - 300) / 2);
    Display.setTitle("Gears");

    try {
      Display.create();
    } catch (LWJGLException e) {
      // This COULD be because of a bug! A delay followed by a new attempt is supposed to fix it.
      e.printStackTrace();
      try {
        Thread.sleep(1000);
      } catch (InterruptedException ignored) {
      }

      Display.create();
    }

    // setup ogl
    FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] {5.0f, 5.0f, 10.0f, 0.0f});
    FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] {0.8f, 0.1f, 0.0f, 1.0f});
    FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] {0.0f, 0.8f, 0.2f, 1.0f});
    FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] {0.2f, 0.2f, 1.0f, 1.0f});

    pos.flip();
    red.flip();
    green.flip();
    blue.flip();

    glLight(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    /* make the gears */
    gear1 = glGenLists(1);
    glNewList(gear1, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
    glEndList();

    gear2 = glGenLists(1);
    glNewList(gear2, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
    glEndList();

    gear3 = glGenLists(1);
    glNewList(gear3, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
    gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
    glEndList();

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);

    System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
    System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
    System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
    System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
    System.err.println();
    System.err.println(
        "glLoadTransposeMatrixfARB() supported: "
            + GLContext.getCapabilities().GL_ARB_transpose_matrix);
    if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
      // --- not using extensions
      glLoadIdentity();
    } else {
      // --- using extensions
      final FloatBuffer identityTranspose =
          BufferUtils.createFloatBuffer(16)
              .put(new float[] {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});
      identityTranspose.flip();
      glLoadTransposeMatrixARB(identityTranspose);
    }

    float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -40.0f);
  }
Пример #20
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 ----");
  }
Пример #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
  private void handleInput() {
    while (Keyboard.next()) {
      if (Keyboard.isRepeatEvent()) {
        continue;
      }

      if (!Keyboard.getEventKeyState()) {
        continue;
      }

      if (Keyboard.getEventKey() == Keyboard.KEY_A) {
        broadcastController.requestAuthToken(username, password);
      } else if (Keyboard.getEventKey() == Keyboard.KEY_S) {
        broadcastController.setStreamInfo(username, "Java Game", "Fun times");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_P) {
        if (broadcastController.getIsPaused()) {
          broadcastController.resumeBroadcasting();
        } else {
          broadcastController.pauseBroadcasting();
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_SPACE) {
        if (broadcastController.getIsBroadcasting()) {
          broadcastController.stopBroadcasting();
        } else {
          VideoParams videoParams =
              broadcastController.getRecommendedVideoParams(
                  Display.getDisplayMode().getWidth(),
                  Display.getDisplayMode().getHeight(),
                  broadcastFramesPerSecond);
          videoParams.verticalFlip = true;

          broadcastController.startBroadcasting(videoParams);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_R) {
        broadcastController.runCommercial();
      } else if (Keyboard.getEventKey() == Keyboard.KEY_I) {
        if (ingestTester != null) {
          broadcastController.cancelIngestTest();
          ingestTester = null;
        } else {
          ingestTester = broadcastController.startIngestTest();
          ingestTester.setListener(this);
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_G) {
        broadcastController.requestGameNameList("final");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_1) {
        broadcastController.sendActionMetaData(
            "TestAction",
            broadcastController.getCurrentBroadcastTime(),
            "Something cool happened",
            "{ \"MyValue\" : \"42\" }");
      } else if (Keyboard.getEventKey() == Keyboard.KEY_2) {
        if (metaDataSpanSequenceId == -1) {
          metaDataSpanSequenceId =
              broadcastController.startSpanMetaData(
                  "TestSpan",
                  broadcastController.getCurrentBroadcastTime(),
                  "Something cool just started happening",
                  "{ \"MyValue\" : \"42\" }");
        } else {
          broadcastController.endSpanMetaData(
              "TestSpan",
              broadcastController.getCurrentBroadcastTime(),
              metaDataSpanSequenceId,
              "Something cool just stopped happening",
              "{ \"MyValue\" : \"42\" }");
          metaDataSpanSequenceId = -1;
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_C) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connect(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_V) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.disconnect();
          } else {
            chatController.connectAnonymous(username);
          }
        }
      } else if (Keyboard.getEventKey() == Keyboard.KEY_M) {
        if (chatController != null) {
          if (chatController.getIsConnected()) {
            chatController.sendChatMessage("Test chat message: " + System.currentTimeMillis());
          }
        }
      }
    }
  }